import axios from "../../../config/axios";
import { CreateCompanyType, CreateIndustryType } from "../types/CompanyTypes";

export const getIndustries = async (
  page: number,
  search: string,
  isActive: string
) => {
  let query = `?page=${page}&q=${search}`;
  if (isActive) {
    query += `&isActive=${isActive === "active" ? "1" : "0"}`;
  }
  const { data } = await axios.get(`/industries/list${query}`);
  return data;
};

export const createIndustry = async (params: CreateIndustryType) => {
  const { data } = await axios.post("/industries", params);
  return data;
};

export const deleteIndustry = async (id: string) => {
  const { data } = await axios.delete(`/industries/${id}`);
  return data;
};

export const changeStatusIndustry = async (id: string) => {
  const { data } = await axios.put(`/industries/${id}/status`);
  return data;
};

export const updateIndustry = async (
  id: string,
  params: CreateIndustryType
) => {
  const { data } = await axios.patch(`/industries/${id}`, params);
  return data;
};

export const getIndustryDetail = async (id: string) => {
  const { data } = await axios.get(`/industries/${id}`);
  return data;
};

export const createCompany = async (params: CreateCompanyType) => {
  const { data } = await axios.post("/companies", params);
  return data;
};

export const getCompanies = async (page: number) => {
  const { data } = await axios.get(`/companies/list?page=${page}`);
  return data;
};

export const deleteCompany = async (id: string) => {
  const { data } = await axios.delete(`/companies/${id}`);
  return data;
};

export const getCompanyDetail = async (id: string) => {
  const { data } = await axios.get(`/companies/${id}`);
  return data;
};

export const updateCompany = async (id: string, params: CreateCompanyType) => {
  const { data } = await axios.patch(`/companies/${id}`, params);
  return data;
};

export const toggleStatusCompany = async (id: string) => {
  const { data } = await axios.patch(`/companies/${id}/toggle-status`);
  return data;
};
