import { apiRequest, type ApiSession } from './client'

export type InboxItemDTO = {
  id: string
  projectId: string
  sourceType: string
  title: string
  body: string
  status: string
  createdAt: string
  updatedAt: string
}

export type InboxSuggestionDTO = {
  id: string
  kind: 'task' | 'note' | 'source'
  title: string
  body: string
}

export type AnalyzeInboxResponseDTO = {
  suggestions: InboxSuggestionDTO[]
}

export type ConfirmInboxResponseDTO = {
  createdCount: number
}

export type CaptureInboxInput = {
  sourceType: string
  title: string
  body: string
}

export async function captureProjectInbox(session: ApiSession, projectId: string, input: CaptureInboxInput) {
  return apiRequest<InboxItemDTO>(`/api/v1/projects/${projectId}/inbox`, {
    method: 'POST',
    token: session.token,
    body: input,
  })
}

export async function analyzeInboxItem(session: ApiSession, inboxId: string) {
  return apiRequest<AnalyzeInboxResponseDTO>(`/api/v1/inbox/${inboxId}/analyze`, {
    method: 'POST',
    token: session.token,
  })
}

export async function confirmInboxItem(session: ApiSession, inboxId: string, suggestionIds: string[]) {
  return apiRequest<ConfirmInboxResponseDTO>(`/api/v1/inbox/${inboxId}/confirm`, {
    method: 'POST',
    token: session.token,
    body: { suggestionIds },
  })
}
