import axios from "@/config/axios";
import type {
  CreateTicketCategoryType,
  CreateTicketMessageType,
  ITicketCategoriesResponse,
  ITicketsResponse,
  ITicketResponse,
} from "../types/Types";

export const getTickets = async (
  page: number = 1,
  limit: number = 10
): Promise<ITicketsResponse> => {
  const { data } = await axios.get("/admin/tickets", {
    params: { page, limit },
  });
  return data;
};

export const addTicketMessage = async (
  ticketId: string,
  params: CreateTicketMessageType
) => {
  const { data } = await axios.post(
    `/admin/tickets/${ticketId}/add-message`,
    params
  );
  return data;
};

export const getTicket = async (ticketId: string): Promise<ITicketResponse> => {
  const { data } = await axios.get(`/admin/tickets/${ticketId}`);
  return data;
};

export const getTicketCategories = async (): Promise<
  ITicketCategoriesResponse
> => {
  const { data } = await axios.get("/tickets/categories");
  return data;
};

export const getTicketCategory = async (categoryId: string) => {
  const { data } = await axios.get(`/admin/tickets/category/${categoryId}`);
  return data;
};

export const createTicketCategory = async (
  params: CreateTicketCategoryType
) => {
  const { data } = await axios.post("/admin/tickets/category", params);
  return data;
};

export const updateTicketCategory = async (
  categoryId: string,
  params: CreateTicketCategoryType
) => {
  const { data } = await axios.put(
    `/admin/tickets/category/${categoryId}`,
    params
  );
  return data;
};

export const deleteTicketCategory = async (categoryId: string) => {
  const { data } = await axios.delete(`/admin/tickets/category/${categoryId}`);
  return data;
};
