import { externalParam } from "@/external-portal/services/portalOutgoingService";
import { withHeaders } from "@/record-management/services/api/withHeaders";
import recordAxiosInstance from "@/shared/services/recordAxiosInstance";
import { AdoptTemplateTypes } from "@/super-admin/components/templates/template";
import { CreateTemplateTypes } from "@/super-admin/components/templates/types/templateTypes";

export const getDelegationTemplates = async () => {
  const { data } = await recordAxiosInstance.get("/record-templates/global", {
    headers: withHeaders(),
  });
  return data;
};

export const getDelegationTemplateById = async (
  id: string,
  params: externalParam,
) => {
  const { data } = await recordAxiosInstance.get(`/record-templates/${id}`, {
    headers: withHeaders(),
    ...params,
  });
  return data;
};

export const createDelegationTemplate = async (
  template: CreateTemplateTypes,
) => {
  const { data } = await recordAxiosInstance.post(
    `/record-templates/global/delegation`,
    template,
    {
      headers: withHeaders(),
    },
  );
  return data;
};

export const updateDelegationTemplate = async (
  id: string,
  template: CreateTemplateTypes,
) => {
  const { data } = await recordAxiosInstance.patch(
    `/record-templates/global/${id}`,
    template,
    {
      headers: withHeaders(),
    },
  );
  return data;
};

export const deleteDelegationTemplate = async (id: string) => {
  const { data } = await recordAxiosInstance.delete(`/record-templates/${id}`, {
    headers: withHeaders(),
  });
  return data;
};

export const adoptDelegationTemplate = async (item: AdoptTemplateTypes) => {
  const { data } = await recordAxiosInstance.post(
    `/record-templates/adopt-to-unit`,
    item,
    {
      headers: withHeaders(),
    },
  );
  return data;
};
