import type {
  GetDetailSiteSetting,
  GetSiteSetting,
} from "@/pages/tour-settings/lib/types";
import httpClient from "@/shared/config/api/httpClient";
import { SITE_SETTING } from "@/shared/config/api/URLs";
import type { AxiosResponse } from "axios";

const createSiteSetting = async (body: {
  address: string;
  latitude: string;
  longitude: string;
  telegram: string;
  instagram: string;
  telegram_chat: string;
  linkedin: string;
  facebook: string;
  twitter: string;
  email: string;
  main_phone: string;
  other_phone: string;
}) => {
  const res = await httpClient.post(SITE_SETTING, body);
  return res;
};

const updateSiteSetting = async ({
  body,
  id,
}: {
  id: number;
  body: {
    address: string;
    latitude: string;
    longitude: string;
    telegram: string;
    telegram_chat: string;
    linkedin: string;
    instagram: string;
    facebook: string;
    twitter: string;
    email: string;
    main_phone: string;
    other_phone: string;
  };
}) => {
  const res = await httpClient.patch(`${SITE_SETTING}${id}/`, body);
  return res;
};

const getSiteSetting = async (): Promise<AxiosResponse<GetSiteSetting>> => {
  const res = await httpClient.get(SITE_SETTING);
  return res;
};

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

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

export {
  createSiteSetting,
  deleteSiteSetting,
  getDetailSiteSetting,
  getSiteSetting,
  updateSiteSetting,
};
