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

const ProjectRepository = {
  getProjectList: () => api.get("/api/project/list"),
  getProjectByprojectId: (projetid) =>
    api.get(`/api/project/details/${projetid}`),

  getProjectAllocation: (projectId, organizationId, serviceId) => {
    let url = `/api/project/allocation/${projectId}`;

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

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

    return api.get(url);
  },


  getEmployeesByProject: (projectId) =>
    api.get(`/api/Project/employees/get/${projectId}`),

  manageProject: (data) => api.post("/api/project", data),

  manageProjectAllocation: (data) => api.post("/api/project/allocation", data),

  manageProjectInfra: (data) => api.post("/api/project/manage-infra", data),
  manageProjectTasks: (data) => api.post("/api/project/task", data),
  deleteProjectTask: (id) => api.delete(`/api/project/task/${id}`),

  updateProject: (id, data) => api.put(`/api/project/update/${id}`, data),
  deleteProject: (id) => api.delete(`/projects/${id}`),
  getProjectsByEmployee: (id) =>
    api.get(`/api/project/assigned-projects/${id}`),
  getProjectsAllocationByEmployee: (id) =>
    api.get(`/api/project/allocation-histery/${id}`),
  updateProjectsByEmployee: (id, data) =>
    api.post(`/api/project/assign-projects/${id}`, data),
  projectNameList: () => api.get("/api/project/list/basic"),

  getProjectDetails: (id) => api.get(`/api/project/details/${id}`),
  getProjectInfraByproject: (id) => api.get(`/api/project/infra-details/${id}`),
  getProjectTasksByWorkArea: (workAreaId, serviceId) => {
    let url = `/api/project/tasks/${workAreaId}`;
    if (serviceId) {
      url += `?serviceId=${serviceId}`;
    }

    return api.get(url);
  },
  getProjectTasksByEmployee: (id, fromDate, toDate) =>
    api.get(
      `/api/project/tasks-employee/${id}?fromDate=${fromDate}&toDate=${toDate}`
    ),

  // Permission Managment for Employee at Project Level

  getProjectLevelEmployeeList: (projectId) => api.get(`/api/Project/get/proejct-level/employees/${projectId}`),
  getProjectLevelModules: () => api.get(`/api/Project/get/proejct-level/modules`),
  getProjectLevelEmployeePermissions: (employeeId, projectId) => api.get(`/api/Project/get/project-level-permission/employee/${employeeId}/project/${projectId}`),
  updateProjectLevelEmployeePermission: (data) => api.post(`/api/Project/assign/project-level-permission`, data),
  getAllProjectLevelPermission: (projectId) => api.get(`/api/Project/get/all/project-level-permission/${projectId}`),


  // Services
  getProjectAssignedServices: (projectId) => api.get(`/api/Project/get/assigned/services/${projectId}`),
  getProjectAssignedOrganizations: (projectId) => api.get(`/api/Project/get/assigned/organization/${projectId}`)
};

export const TasksRepository = {
  assignTask: (data) => api.post("/api/task/assign", data),
  // reportTask:(data)=>api.post("/api/task/report",data)
};
export default ProjectRepository;
