import type {
  AllGetBanner,
  DetailGetBanner,
} from "@/pages/site-banner/lib/types";
import httpClient from "@/shared/config/api/httpClient";
import { BANNER } from "@/shared/config/api/URLs";
import type { AxiosResponse } from "axios";

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

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

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

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

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

export { bannerDelete, createBanner, getBanner, getBannerDetail, updateBanner };
