import type { Contact } from '../contacts/types' import type { Department } from '../departments/types' import type { Service } from '../services/types' import type { User } from '../users/types' export type TicketOrigin = 'automatic' | 'manual' | 'widget' export type TicketMetrics = { /** Time in seconds the contact waited before a user picked up the ticket. */ waitingTime?: number /** Time in seconds the contact waited after the bot handed off to a human. */ waitingTimeAfterBot?: number /** Total time in seconds with active messaging (first to last message). */ messagingTime?: number /** Total open time in seconds from ticket open to close. */ ticketTime?: number /** Sum of waiting times across all transfers. */ waitingTimeTransfersSum?: number /** Number of times the ticket was transferred. */ ticketTransferCount?: number /** Average waiting time per transfer. */ waitingTimeTransfersAvg?: number isActiveTicket?: boolean } export type Ticket = { id: string isOpen: boolean comments: string | null protocol: string | null origin: TicketOrigin | null metrics: TicketMetrics startedAt: string | null endedAt: string | null isDistributing: boolean count: number | null accountId: string departmentId: string contactId: string userId: string | null serviceId: string | null firstMessageId: string | null lastMessageId: string | null currentTicketTransferId: string | null createdAt: string updatedAt: string // relationships contact?: Contact department?: Department user?: User | null service?: Service | null } export type TicketRelationships = 'contact' | 'department' | 'user' | 'service' export type CreateTicketPayload = { contactId: string departmentId: string userId?: string comments?: string origin?: TicketOrigin } export type UpdateTicketPayload = { departmentId?: string userId?: string | null comments?: string | null isOpen?: boolean } /** * Body for `PUT /tickets/close-many`. * * Either close an explicit list of tickets by id, or close every open ticket * matching a query. For the query variant the outer `query` is an object whose * `query` field is a JSON-stringified list query (e.g. `JSON.stringify({ where: {} })`); * the backend always forces `where.isOpen = true`. */ export type CloseManyTicketsPayload = | { ids: string[]; ticketTopicIds?: string[] | string; comments?: string } | { allContactsSelected: true; query: { query: string } }