import axiosInstance from '@/config/axios' import { texts } from '@/texts' import { parseRemittanceList, unwrapApiDataUnknown } from '@/helpers/listResponse' export interface SupportTicketMessage { id: string senderId: string body: string isAdmin: boolean createdAt: string } export interface SupportTicket { id: string userId: string subject: string category: string priority: string status: string lastMessageAt: string closedAt: string | null createdAt: string user: { mobile: string; displayName: string | null } messages: SupportTicketMessage[] } export const SUPPORT_CATEGORY_LABELS: Record = { ...texts.support.categories } export const SUPPORT_PRIORITY_LABELS: Record = { ...texts.support.priorities } export const SUPPORT_STATUS_LABELS: Record = { ...texts.support.status } export const SUPPORT_ADMIN_STATUS_LABELS: Record = { ...texts.support.adminStatus } const unwrapTicket = (raw: unknown): SupportTicket => unwrapApiDataUnknown(raw) as SupportTicket export async function listMySupportTickets(): Promise { const response = await axiosInstance.get('support-tickets/me', { params: { pageSize: 100, sort: '-lastMessageAt' } }) return parseRemittanceList(response.data).items } export async function getMySupportTicket(id: string): Promise { const response = await axiosInstance.get(`support-tickets/${id}`) return unwrapTicket(response.data) } export async function createSupportTicket(payload: { subject: string category: string priority: string message: string }): Promise { const response = await axiosInstance.post('support-tickets', payload) return unwrapTicket(response.data) } export async function replyToSupportTicket(id: string, message: string): Promise { const response = await axiosInstance.post(`support-tickets/${id}/replies`, { message }) return unwrapTicket(response.data) } export async function getAdminSupportTicket(id: string): Promise { const response = await axiosInstance.get(`admin/support-tickets/${id}`) return unwrapTicket(response.data) } export async function adminReplyToSupportTicket(id: string, message: string): Promise { const response = await axiosInstance.post(`admin/support-tickets/${id}/replies`, { message }) return unwrapTicket(response.data) } export async function updateSupportTicketStatus(id: string, status: string): Promise { const response = await axiosInstance.patch(`admin/support-tickets/${id}/status`, { status }) return unwrapTicket(response.data) }