You are a Senior Full Stack Engineer.

Project:
Training Management System (TMS)

Current status:

- Sprint 5 approved
- Responsive Audit approved
- Mobile UX Review approved

Current task:
Implement Sprint 6 Phase 1:
Audit Log Foundation

Important constraints:

- Do NOT change folder structure.
- Do NOT migrate ORM.
- Do NOT rename tables.
- Do NOT rename columns.
- Reuse existing Auth.js.
- Reuse existing Drizzle ORM.
- Reuse existing UI components.
- Keep Thai UI.
- Minimal-impact changes only.

Requirements:

1. Create Audit Log module.

Route:

- /dashboard/audit-logs

2. Create reusable audit service.

Example:

logAuditEvent({
userId,
module,
action,
entityId,
oldValue,
newValue,
ipAddress
})

3. Track:

Authentication

- LOGIN_SUCCESS
- LOGIN_FAILED

Training Records

- CREATE
- UPDATE
- DELETE

HRD Review

- APPROVE
- REJECT

Course Master

- CREATE
- UPDATE

Training Policy

- CREATE
- UPDATE

Employee Import

- IMPORT

Master Review

- APPROVE
- REJECT

4. Audit Log UI

Columns:

- วันที่
- ผู้ใช้งาน
- โมดูล
- รายการ
- รายละเอียด

5. Filters

- วันที่
- ผู้ใช้งาน
- โมดูล
- รายการ

6. Search

7. Export CSV

8. Thai UI

9. Role

HRD only

10. Output Review File

Create:

docs/sprint-6-phase-1-audit-log-review.md

Include:

1. Summary
2. Files Changed
3. Database Changes
4. Events Implemented
5. Permission Rules
6. Manual Test Checklist
7. Known Limitations
8. Next Phase Recommendation

Return:

- Complete code changes
- Review file
- Migration commands if required
