import api from "../lib/axios";
import { CurrentUser } from "../types/auth";
import { AttendanceRecord } from "../types/attendance";
import { AxiosRequestConfig } from "axios";

export const dashboardService = {
  getStats: async (options?: AxiosRequestConfig): Promise<any> => {
    const response = await api.get("/dashboard/stats", options);
    return response.data;
  },

  getAllUsers: async (options?: AxiosRequestConfig): Promise<CurrentUser[]> => {
    const response = await api.get("/users", options);
    return response.data;
  },
};

export const attendanceService = {
  checkIn: async (method: string, options?: AxiosRequestConfig): Promise<any> => {
    const response = await api.post("/attendance/check-in", { method }, options);
    return response.data;
  },

  checkOut: async (method: string, options?: AxiosRequestConfig): Promise<AttendanceRecord> => {
    const response = await api.post("/attendance/check-out", { method }, options);
    return response.data;
  },

  getToday: async (options?: AxiosRequestConfig): Promise<AttendanceRecord[]> => {
    const response = await api.get("/attendance/today", options);
    return response.data;
  },

  getHistory: async (params: any, options?: AxiosRequestConfig): Promise<{ data: AttendanceRecord[], total: number }> => {
    const response = await api.get("/attendance/history", { params, ...options });
    return response.data;
  },

  getAllAttendance: async (params: any, options?: AxiosRequestConfig): Promise<{ data: AttendanceRecord[], total: number }> => {
    const response = await api.get("/attendance/all", { params, ...options });
    return response.data;
  },
};
