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

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

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

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

    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: (provideAll) => api.get(`/api/project/list/basic?provideAll=${provideAll}`),

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

    return api.get(url);
  },
  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}`),
   getProjectAssignedOrganizationsName: (projectId) =>
    api.get(`/api/Project/get/assigned/organization/dropdown/${projectId}`),

  getEmployeeForTaskAssign: (projectId, serviceId, organizationId) => {
    let url = `/api/Project/get/task/team/${projectId}`;

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

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

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