import apiClient from './client'

export interface DeadlineMessageResponse {
  id: string
  subject: string | null
  from_address: string | null
  to_addresses: string[] | null
  direction: 'inbound' | 'outbound'
  pec_type: string
  state: string
  mailbox_id: string
  deadline_at: string | null
  deadline_note: string | null
  is_overdue: boolean
  received_at: string | null
  sent_at: string | null
  created_at: string
}

export interface DeadlineSetRequest {
  deadline_at: string | null
  deadline_note?: string | null
}

export const deadlinesApi = {
  list: (params?: { days_ahead?: number; include_overdue?: boolean }) =>
    apiClient.get<DeadlineMessageResponse[]>('/deadlines', { params }).then((r) => r.data),

  setDeadline: (messageId: string, data: DeadlineSetRequest) =>
    apiClient.post<DeadlineMessageResponse>(`/messages/${messageId}/deadline`, data).then((r) => r.data),
}
