import type {
  GetAllEmployeesData,
  GetDetailEmployeesData,
} from "@/pages/employees/lib/type";
import httpClient from "@/shared/config/api/httpClient";
import { GET_ALL_EMPLOYEES } from "@/shared/config/api/URLs";
import type { AxiosResponse } from "axios";

const getAllEmployees = async ({
  page,
  page_size,
}: {
  page: number;
  page_size: number;
}): Promise<AxiosResponse<GetAllEmployeesData>> => {
  const response = await httpClient.get(GET_ALL_EMPLOYEES, {
    params: { page, page_size },
  });
  return response;
};

const getDetailEmployees = async ({
  id,
}: {
  id: number;
}): Promise<AxiosResponse<GetDetailEmployeesData>> => {
  const response = await httpClient.get(`${GET_ALL_EMPLOYEES}${id}/`);
  return response;
};

const deleteEmployees = async ({ id }: { id: number }) => {
  const response = await httpClient.delete(`${GET_ALL_EMPLOYEES}${id}/`);
  return response;
};

const editEmployees = async ({
  id,
  body,
}: {
  id: number;
  body: {
    first_name: string;
    last_name: string;
    phone: string;
    email: string | null;
    role: "buxgalter" | "operator";
  };
}) => {
  const response = await httpClient.patch(`${GET_ALL_EMPLOYEES}${id}/`, body);
  return response;
};

const createEmployees = async ({
  body,
}: {
  body: {
    first_name: string;
    last_name: string;
    phone: string;
    email: string | null;
    role: "buxgalter" | "operator";
  };
}) => {
  const response = await httpClient.post(`${GET_ALL_EMPLOYEES}`, body);
  return response;
};

export {
  createEmployees,
  deleteEmployees,
  editEmployees,
  getAllEmployees,
  getDetailEmployees,
};
