import api from "./api.js";
import { unwrapData, unwrapList } from "./http.js";

export async function listTickets(query = {}) {
  const res = await api.get("/tickets", { params: query });
  return unwrapList(res);
}

export async function createTicket(payload) {
  const res = await api.post("/tickets", payload);
  return unwrapData(res);
}

export async function updateTicket(id, payload) {
  const res = await api.put(`/tickets/${id}`, payload);
  return unwrapData(res);
}

export async function getTicket(id) {
  const res = await api.get(`/tickets/${id}`);
  return unwrapData(res);
}

export async function deleteTicket(id) {
  const res = await api.delete(`/tickets/${id}`);
  return unwrapData(res);
}

export async function listTicketLogs(query = {}) {
  const res = await api.get("/tickets_logs", { params: query });
  return unwrapList(res);
}
