import axios from "@/config/axios";
import { TemplateType, TemplatesResponseType } from "../types/Types";
import axiosDanak from "@/config/axiosDanak";

export const saveTemplate = async (params: TemplateType) => {
  const { data } = await axios.post("/templates", params);
  return data;
};

export const getTemplates = async (): Promise<TemplatesResponseType> => {
  const { data } = await axios.get("/templates");
  return data;
};

export const setSelectedTemplate = async (id: string) => {
  const { data } = await axios.patch(`/templates/${id}/set-selected`);
  return data;
};

export const getTemplate = async (id: string) => {
  const { data } = await axios.get(`/templates/${id}`);
  return data;
};

export const updateTemplate = async ({
  id,
  params,
}: {
  id: string;
  params: TemplateType;
}) => {
  const { data } = await axios.patch(`/templates/${id}`, params);
  return data;
};

export const deleteTemplate = async (id: string) => {
  const { data } = await axios.delete(`/templates/${id}`);
  return data;
};

export const singleUpload = async (file: File) => {
  const formData = new FormData();
  formData.append("file", file);

  const { data } = await axiosDanak.post("/uploader/single-file", formData);

  return data;
};
