import type {
  GetAllHelpPage,
  GetAllOfferta,
  GetDetailHelpPage,
  GetDetailOfferta,
} from "@/pages/site-page/lib/types";
import httpClient from "@/shared/config/api/httpClient";
import { HELP_PAGE, OFFERTA } from "@/shared/config/api/URLs";
import type { AxiosResponse } from "axios";

const createOfferta = async ({
  body,
}: {
  body: {
    title: string;
    title_ru: string;
    content: string;
    content_ru: string;
    person_type: "individual" | "legal_entity";
    is_active: boolean;
  };
}) => {
  const res = await httpClient.post(OFFERTA, body);
  return res;
};

const updateOfferta = async ({
  body,
  id,
}: {
  id: number;
  body: {
    title: string;
    title_ru: string;
    content: string;
    content_ru: string;
    person_type?: "individual" | "legal_entity";
    is_active?: boolean;
  };
}) => {
  const res = await httpClient.patch(`${OFFERTA}${id}/`, body);
  return res;
};

const getAllOfferta = async (params: {
  page: number;
  page_size: number;
  person_type?: "individual" | "legal_entity";
}): Promise<AxiosResponse<GetAllOfferta>> => {
  const res = await httpClient.get(OFFERTA, { params });
  return res;
};

const getOneOfferta = async (
  id: number,
): Promise<AxiosResponse<GetDetailOfferta>> => {
  const res = await httpClient.get(`${OFFERTA}${id}/`);
  return res;
};

const deleteOfferta = async (id: number) => {
  const res = await httpClient.delete(`${OFFERTA}${id}/`);
  return res;
};

const createHelpPage = async ({
  body,
}: {
  body: {
    title: string;
    title_ru: string;
    content_ru: string;
    content: string;
    page_type: "privacy_policy" | "user_agreement";
    is_active: boolean;
  };
}) => {
  const res = await httpClient.post(HELP_PAGE, body);
  return res;
};

const getAllHelpPage = async (params: {
  page: number;
  page_size: number;
  page_type?: "privacy_policy" | "user_agreement";
}): Promise<AxiosResponse<GetAllHelpPage>> => {
  const res = await httpClient.get(HELP_PAGE, { params });
  return res;
};

const getDetailHelpPage = async (
  id: number,
): Promise<AxiosResponse<GetDetailHelpPage>> => {
  const res = await httpClient.get(`${HELP_PAGE}${id}/`);
  return res;
};

const updateHelpPage = async ({
  body,
  id,
}: {
  id: number;
  body: {
    title: string;
    title_ru: string;
    content_ru: string;
    content: string;
    page_type?: "privacy_policy" | "user_agreement";
    is_active?: boolean;
  };
}) => {
  const res = await httpClient.patch(`${HELP_PAGE}${id}/`, body);
  return res;
};

const deleteHelpPage = async (id: number) => {
  const res = await httpClient.delete(`${HELP_PAGE}${id}/`);
  return res;
};

export {
  createHelpPage,
  createOfferta,
  deleteHelpPage,
  deleteOfferta,
  getAllHelpPage,
  getAllOfferta,
  getDetailHelpPage,
  getOneOfferta,
  updateHelpPage,
  updateOfferta,
};
