-- Optimization for Attendance Reports
-- These indexes speed up the frequent queries used in reportAttendance and reportAttendanceByEmployee

-- Composite index for fast lookup of an employee's attendance on a specific date
-- or range of dates (essential for reportAttendanceByEmployee loop)
CREATE INDEX IF NOT EXISTS idx_attendances_employee_date ON attendances (employee_id, date);

-- Index for filtering by date alone (e.g. daily reports for all employees)
CREATE INDEX IF NOT EXISTS idx_attendances_date ON attendances (date);

-- Index for filtering by company
CREATE INDEX IF NOT EXISTS idx_attendances_company ON attendances (company_id);

-- Index for modified (sorting)
CREATE INDEX IF NOT EXISTS idx_attendances_modified ON attendances (modified);

-- Index for employee name (sorting)
CREATE INDEX IF NOT EXISTS idx_employees_name ON employees (employee_name);
