import axios from "../../../config/axios";
import type {
  AboutUsResponse,
  BannersResponse,
  CreateAboutUs,
  CreateDocumentType,
  CreateFaqType,
  CreatePricingItem,
  DocumentTypesResponse,
  FaqDetailResponse,
  FaqResponse,
  PricingResponse,
  ShopResponse,
  UpdateBannerType,
  UpdateShopType,
  UpdateSiteSetting,
} from "../types/Types";
import { FaqPageEnum, SiteSettingPageEnum } from "../enum/Enum";

export const getAboutUs = async (): Promise<AboutUsResponse> => {
  const { data } = await axios.get("/about-us");
  return data;
};

export const createAboutUs = async (params: CreateAboutUs) => {
  const { data } = await axios.post("/admin/settings/about-us", params);
  return data;
};

export const deleteAboutUs = async (id: string) => {
  const { data } = await axios.delete(`/admin/settings/about-us/${id}`);
  return data;
};

export const getFaq = async (page: FaqPageEnum): Promise<FaqResponse> => {
  const { data } = await axios.get(`/admin/settings/faqs?page=${page}`);
  return data;
};

export const createFaq = async (params: CreateFaqType) => {
  const { data } = await axios.post("/admin/settings/faqs", params);
  return data;
};

export const deleteFaq = async (id: string) => {
  const { data } = await axios.delete(`/admin/settings/faqs/${id}`);
  return data;
};

export const getFaqDetail = async (id: string): Promise<FaqDetailResponse> => {
  const { data } = await axios.get(`/admin/settings/faqs/${id}`);
  return data;
};

export const updateFaq = async (id: string, params: CreateFaqType) => {
  const { data } = await axios.patch(`/admin/settings/faqs`, {
    ...params,
    faqId: id,
  });
  return data;
};

export const getSiteSetting = async (
  page?: SiteSettingPageEnum
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
): Promise<any> => {
  const url = page ? `/site-setting?name=${page}` : `/site-setting`;
  const { data } = await axios.get(url);
  return data;
};

export const updateSiteSetting = async (params: UpdateSiteSetting) => {
  const { data } = await axios.post(`/admin/site-setting/update`, params);
  return data;
};

export const createDocument = async (params: CreateDocumentType) => {
  const { data } = await axios.post(`/admin/settings/document-types`, params);
  return data;
};

export const getDocuments = async (): Promise<DocumentTypesResponse> => {
  const { data } = await axios.get(`/seller/document-types`);
  return data;
};

export const deleteDocument = async (id: string) => {
  const { data } = await axios.delete(`/admin/settings/document-types/${id}`);
  return data;
};

export const getPricing = async (): Promise<PricingResponse> => {
  const { data } = await axios.get(`/admin/financial/pricing`);
  return data;
};

export const createPricing = async (params: CreatePricingItem) => {
  const { data } = await axios.post("/admin/financial/pricing", params);
  return data;
};

export const updatePricing = async (id: string, params: CreatePricingItem) => {
  const { data } = await axios.patch(`/admin/financial/pricing/${id}`, params);
  return data;
};

export const deletePricing = async (id: string) => {
  const { data } = await axios.delete(`/admin/financial/pricing/${id}`);
  return data;
};

export const getShop = async (): Promise<ShopResponse> => {
  const { data } = await axios.get(`/admin/shop`);
  return data;
};

export const updateShop = async (params: UpdateShopType) => {
  const { data } = await axios.patch(`/admin/shop`, params);
  return data;
};

export const getBanners = async (): Promise<BannersResponse> => {
  const { data } = await axios.get(`/admin/medias/banners`);
  return data;
};

export const deleteBanner = async (id: string) => {
  const { data } = await axios.delete(`/admin/medias/banner/${id}`);
  return data;
};

export const updateBanner = async (id: string, params: UpdateBannerType) => {
  const { data } = await axios.post(`/admin/medias/banner/${id}`, params);
  return data;
};

export const createBanner = async (params: UpdateBannerType) => {
  const { data } = await axios.post(`/admin/medias/banner`, params);
  return data;
};
