import {
  AttachmentSearch,
  AttachmentUpload,
} from "@/components/models/management/Attachments";

import { request } from "@/components/service/index";
export const AttachmentsService = {
  upload: (payload: AttachmentUpload) => {
    return request.post("/api/attachments/upload", payload);
  },
  delete: (id: Number) => {
    return request.delete(`/api/attachments/${id}`, {});
  },
  view: (id: number) => {
    return request.get(`/api/attachments/${id}`, {});
  },
  update: (id: number, payload: AttachmentUpload) => {
    return request.put(`/api/attachments/${id}/update`, payload);
  },

  readTextByPath: (objectName: string) => {
    return request.get(
      `/api/attachments/readYamlText?objectName=${objectName}`,
      {},
    );
  },
  downloadFile: (objectName: string) => {
    return request.getFile(
      `/api/attachments/download?objectName=${objectName}`,
      {},
    );
  },
  search: (payload: AttachmentSearch) => {
    return request.get("/api/attachments/search", payload);
  },
};
