import type { AllSeoData, DetailSeoData } from "@/pages/seo/lib/types";
import httpClient from "@/shared/config/api/httpClient";
import { SITE_SEO } from "@/shared/config/api/URLs";
import type { AxiosResponse } from "axios";

const createSeo = async (body: FormData) => {
  const res = await httpClient.post(SITE_SEO, body, {
    headers: { "Content-Type": "multipart/form-data" },
  });
  return res;
};

const getAllSeo = async (params: {
  page: number;
  page_size: number;
}): Promise<AxiosResponse<AllSeoData>> => {
  const res = await httpClient.get(SITE_SEO, { params });
  return res;
};

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

const updateSeo = async ({ body, id }: { id: number; body: FormData }) => {
  const res = await httpClient.patch(`${SITE_SEO}${id}/`, body, {
    headers: { "Content-Type": "multipart/form-data" },
  });
  return res;
};

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

export { createSeo, deleteSeo, getAllSeo, getDetailSeo, updateSeo };
