import api from "src/api";

export const getServicesByConvenio = async (partnerAgreementId) => {
  const { data } = await api.get(`/associado/partner-agreement-service/partner/${partnerAgreementId}`);
  return data.payload;
};

export const getConvenioService = async (id) => {
  const { data } = await api.get(`/associado/partner-agreement-service/${id}`);
  return data.payload;
};

export const getServicesByPartner = async (partnerAgreementId) => {
  const { data } = await api.get(`/partner-agreement-service/partner/${partnerAgreementId}`);
  return data.payload;
};

export const getPartnerAgreementService = async (id) => {
  const { data } = await api.get(`/partner-agreement-service/${id}`);
  return data.payload;
};

export const createService = async (payload) => {
  const { data } = await api.post("/partner-agreement-service", payload);
  return data.payload;
};

export const updateService = async (id, payload) => {
  const { data } = await api.put(`/partner-agreement-service/${id}`, payload);
  return data.payload;
};

export const deleteService = async (id) => {
  await api.delete(`/partner-agreement-service/${id}`);
};

export const uploadServiceMedia = async (id, file) => {
  const form = new FormData();
  form.append("file", file);
  const { data } = await api.post(`/partner-agreement-service/${id}/media`, form, {
    headers: { "Content-Type": "multipart/form-data" },
  });
  return data.payload;
};

export const deleteServiceMedia = async (id, mediaId) => {
  await api.delete(`/partner-agreement-service/${id}/media/${mediaId}`);
};
