import chronicleInstance from "@/shared/services/chronicleInstance";
import {
  BrandingResponse,
  BrandingParam,
  BrandingResponseAPI,
  BrandingParamAPI,
} from "../types/brandTypes";
import axiosInstance from "@/shared/services/axiosInstance";
import { withHeaders } from "@/record-management/services/api/withHeaders";

export async function getBrandingItems(
  siteId: string,
  take?: number,
): Promise<BrandingResponseAPI> {
  try {
    const response = await axiosInstance.get(`/site-settings/list/${siteId}`, {
      headers: withHeaders(),
      params: {
        take: take,
      },
    });

    return response.data;
  } catch (error) {
    throw error;
  }
}
export async function getBrandingItemsUsingDomain(
  siteId: string,
  take?: number,
): Promise<BrandingResponseAPI> {
  try {
    const response = await axiosInstance.get(
      `/site-settings/list/key/${siteId}`,
      {
        params: {
          take: take,
        },
      },
    );

    return response.data;
  } catch (error) {
    throw error;
  }
}

export async function updateBrandingItem(
  id: string,
  data: BrandingParamAPI[],
): Promise<BrandingResponse> {
  const response = await axiosInstance.put(`/site-settings/${id}`, data, {
    headers: withHeaders(),
  });

  return response.data;
}

export async function createBrandingItem(
  data: BrandingParamAPI[],
): Promise<BrandingResponse> {
  const response = await axiosInstance.post(`/site-settings/bulk`, data, {
    headers: withHeaders(),
  });

  return response.data;
}
