import apiClient from './client'

export interface PendingLinkageResponse {
  id: number
  photo_id: number
  tag_id: number | null
  proposed_tag_name: string | null
  resolved_tag_name: string | null
  user_id: number
  user_name: string | null
  user_email: string | null
  status: string
  notes: string | null
  created_at: string
  updated_at: string | null
  photo_filename: string | null
  photo_path: string | null
  photo_media_type: string | null
  photo_tags: string[]
}

export interface PendingLinkagesListResponse {
  items: PendingLinkageResponse[]
  total: number
}

export interface ReviewDecision {
  id: number
  decision: 'approve' | 'deny'
}

export interface ReviewRequest {
  decisions: ReviewDecision[]
}

export interface ReviewResponse {
  approved: number
  denied: number
  tags_created: number
  linkages_created: number
  errors: string[]
}

export interface CleanupResponse {
  deleted_records: number
  errors: string[]
  warnings?: string[]
}

export const pendingLinkagesApi = {
  async listPendingLinkages(statusFilter?: string): Promise<PendingLinkagesListResponse> {
    const { data } = await apiClient.get<PendingLinkagesListResponse>('/api/v1/pending-linkages', {
      params: statusFilter ? { status_filter: statusFilter } : undefined,
    })
    return data
  },

  async reviewPendingLinkages(request: ReviewRequest): Promise<ReviewResponse> {
    const { data } = await apiClient.post<ReviewResponse>('/api/v1/pending-linkages/review', request)
    return data
  },

  async cleanupPendingLinkages(): Promise<CleanupResponse> {
    const { data } = await apiClient.post<CleanupResponse>('/api/v1/pending-linkages/cleanup', {})
    return data
  },
}

export default pendingLinkagesApi


