import { api } from "../utils/axiosClient";

const AttendanceRepository = {
  markAttendance: (data) => api.post("/api/attendance/record", data),
  
  getAttendance: (projectId, organizationId, includeInactive,date) => {
    let url = `/api/attendance/project/team?projectId=${projectId}`;

    const params = [];
    if (organizationId) params.push(`organizationId=${organizationId}`);
    if (includeInactive) params.push(`includeInactive=${includeInactive}`);
    if (date) params.push(`date=${date}`);

    if (params.length > 0) {
      url += `&${params.join("&")}`;    }

    return api.get(url);
  },

  getAttendanceFilteredByDate: (projectId, fromDate, toDate,organizationId) => {
    let url = `api/Attendance/project/log?projectId=${projectId}`;
    if (fromDate) {
      url += `&dateFrom=${fromDate}`;
    }

    if (toDate) {
      url += `&dateTo=${toDate}`;
    }
    if (organizationId) {
      url += `&organizationId=${organizationId}`;
    }
    return api.get(url);
  },

  getAttendanceLogs: (id) => api.get(`api/attendance/log/attendance/${id}`),

    getRegularizeList: (projectId, organizationId, IncludeInActive) => {
    let url = `/api/attendance/regularize?projectId=${projectId}`;

    const params = [];
    if (organizationId) params.push(`organizationId=${organizationId}`);
    if (IncludeInActive) params.push(`IncludeInActive=${IncludeInActive}`);

    if (params.length > 0) {
      url += `&${params.join("&")}`;    }

    return api.get(url);
  },

  getAttendanceByEmployee: (employeeId, fromDate, toDate) => {
    let url = `api/Attendance/log/employee/${employeeId}?`;
    if (fromDate) {
      url += `&dateFrom=${fromDate}`;
    }

    if (toDate) {
      url += `&dateTo=${toDate}`;
    }
    return api.get(url);
  },
};

export default AttendanceRepository;
