import { ENDPOINTS } from '@/constants/endpoints'
import { api } from '@/lib/api'

export async function uploadCustomerKycDocuments(customerId: string, documents: any[] = []) {
  const newDocuments = documents.filter((document) => document?.file instanceof File)
  for (const document of newDocuments) {
    const body = new FormData()
    body.append('file', document.file)
    body.append('document_type', document.document_type || 'identity_document')
    if (document.document_number) body.append('document_number', document.document_number)
    if (document.expiry_date) body.append('expiry_date', document.expiry_date)
    await api.post(ENDPOINTS.CUSTOMERS.KYC_DOCUMENTS(customerId), body, {
      headers: { 'Content-Type': 'multipart/form-data' },
    })
  }
}
