import api from "src/api";

// ─── Rotas do Associado ───────────────────────────────────────────────────────

export const getMyAppointments = async () => {
  const { data } = await api.get("/associado/appointment/my");
  return data.payload;
};

export const createAppointment = async (appointment) => {
  const { data } = await api.post("/associado/appointment", appointment);
  return data.payload;
};

export const cancelAppointment = async (id) => {
  const { data } = await api.put(`/associado/appointment/${id}`, { status: "cancelado" });
  return data.payload;
};

export const updateAppointment = async (id, payload) => {
  const { data } = await api.put(`/associado/appointment/${id}`, payload);
  return data.payload;
};

// ─── Rotas do Parceiro ────────────────────────────────────────────────────────

export const getPartnerAppointments = async () => {
  const { data } = await api.get("/parceiro/appointment");
  return data.payload;
};

export const approveAppointmentParceiro = async (id, payload) => {
  const { data } = await api.put(`/parceiro/appointment/${id}/approve`, payload);
  return data.payload;
};

export const rejectAppointmentParceiro = async (id) => {
  const { data } = await api.put(`/parceiro/appointment/${id}/reject`);
  return data.payload;
};

export const getAdminCounters = async () => {
  const { data } = await api.get("/appointment/admin/counters");
  return data.payload;
};

export const getAdminAppointmentsPaginated = async ({ page = 1, perPage = 10, filter, status } = {}) => {
  const params = { page, per_page: perPage };
  if (filter) params.search = filter;
  if (status) params.status = status;
  const { data } = await api.get("/appointment/admin/list", { params });
  return { data: { result: data.payload } };
};

export const approveAppointment = async (id, payload) => {
  const { data } = await api.put(`/appointment/${id}/approve`, payload);
  return data.payload;
};

export const rejectAppointment = async (id) => {
  const { data } = await api.put(`/appointment/${id}/reject`);
  return data.payload;
};
