import api from 'src/config/api';
import { ChatListItem } from 'src/types/chats';
import { Pagination } from 'src/types/services';
import {
  TicketData,
  FeedbackData,
  Topic,
  CreateTicketResponse,
  TicketAgentStats,
  TicketsPaginationResponse,
} from 'src/types/tickets';

export const getTopicList = () =>
  api.get<Pagination<Topic[]>>('tickets/topics');

export const createTicket = (data: TicketData) =>
  api.post<CreateTicketResponse>('tickets', data);

export const getTicketList = (id, page, status, limit = 20) =>
  api.get<TicketsPaginationResponse>(`users/${id}/tickets`, {
    params: { page, limit, status },
  });

export const getUnassignedTicketList = () =>
  api.get<ChatListItem[]>('users/unassigned-tickets');

export const assignTicket = id =>
  api.post<ChatListItem>(`tickets/${id}/assignment`);

export const closeTicket = id => api.post<ChatListItem>(`tickets/${id}/close`);

export const giveFeedback = (id, data: FeedbackData) =>
  api.post<ChatListItem>(`tickets/${id}/feedbacks`, data);

export const changeTopic = (id: number, topicId: number) =>
  api.put<ChatListItem>(`tickets/${id}/topics/${topicId}`);

export const getTicketAgentStats = (id: number) =>
  api.get<TicketAgentStats>(`tickets/agents/${id}/stats`);
