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

const OrganizationRepository = {
  createOrganization: (data) => api.post("/api/Organization/create", data),
  updateOrganizaion: (id, data) =>
    api.put(`/api/Organization/edit/${id}`, data),
  getOrganizaion: (id) => api.get(`/api/Organization/details/${id}`),
  getOrganizationList: (pageSize, pageNumber, active, sprid, searchString) => {
    return api.get(
      `/api/Organization/list?pageSize=${pageSize}&pageNumber=${pageNumber}&active=${active}&${
        sprid ? `sprid=${sprid}&` : ""
      }searchString=${searchString}`
    );
  },

  getOrganizationBySPRID: (sprid) =>
    api.get(`/api/Organization/list?sprid=${sprid}`),

  assignOrganizationToProject: (data) =>
    api.post(`/api/Organization/assign/project`, data),

  assignOrganizationToTenanat: (organizationId) =>
    api.post(`/api/Organization/assign/tenant/${organizationId}`),

  getOrganizationEmployees: (projectId, organizationId, searchString) => {
    let url = `/api/Employee/list/organizations/${projectId}`;
    const queryParams = [];

    if (organizationId) {
      queryParams.push(`organizationId=${organizationId}`);
    }

    if (searchString) {
      queryParams.push(`searchString=${encodeURIComponent(searchString)}`);
    }

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

    return api.get(url);
  },

  getGlobalOrganization: (pageSize, pageNumber, searchString) =>
    api.get(
      `/api/Organization/list/basic?pageSize=${pageSize}&pageNumber=${pageNumber}&searchString=${searchString}`
    ),
};

export default OrganizationRepository;
