import { api } from "@/lib/api-client";
import type { Ticket, TicketCreateRequest, PaginatedResponse, PaginationParams, ApiSuccessResponse } from "@/types";

export interface TicketListParams extends PaginationParams {
  status?: string;
  type?: string;
  assignee_id?: number;
  source?: string;
}

export const ticketsService = {
  async list(params?: TicketListParams): Promise<PaginatedResponse<Ticket>> {
    return api.get<PaginatedResponse<Ticket>>("/tickets", params as Record<string, string | number | boolean | undefined>);
  },

  async create(data: TicketCreateRequest): Promise<Ticket> {
    return api.post<Ticket>("/tickets", data);
  },

  async update(id: number, data: Partial<Ticket>): Promise<Ticket> {
    return api.patch<Ticket>(`/tickets/${id}`, data);
  },

  async getAssignedToUser(): Promise<Ticket[]> {
    return api.get<Ticket[]>("/tickets/assignedToUser");
  },
};
