import type { BatchDraft, BatchTypeFieldRequirements } from '@/types'

export function fieldRequirementsForBatchType(
  batchType: string,
): BatchTypeFieldRequirements {
  switch (batchType) {
    case 'PATIENT_REGISTRATION':
      return {
        showPatientDemographics: true,
        showEncounterContext: false,
        showEncounterSummaryFields: false,
        showObservations: false,
        showAllergies: false,
        showMedications: false,
      }
    case 'ALLERGY_UPDATE':
      return {
        showPatientDemographics: true,
        showEncounterContext: false,
        showEncounterSummaryFields: false,
        showObservations: false,
        showAllergies: true,
        showMedications: false,
      }
    case 'ENCOUNTER_SUMMARY':
      return {
        showPatientDemographics: true,
        showEncounterContext: true,
        showEncounterSummaryFields: true,
        showObservations: false,
        showAllergies: false,
        showMedications: false,
      }
    case 'MEDICATION_LIST':
      return {
        showPatientDemographics: true,
        showEncounterContext: false,
        showEncounterSummaryFields: false,
        showObservations: false,
        showAllergies: false,
        showMedications: true,
      }
    case 'MIXED':
      return {
        showPatientDemographics: true,
        showEncounterContext: true,
        showEncounterSummaryFields: true,
        showObservations: true,
        showAllergies: true,
        showMedications: true,
      }
    case 'LAB_RESULTS':
      return {
        showPatientDemographics: true,
        showEncounterContext: true,
        showEncounterSummaryFields: false,
        showObservations: true,
        showAllergies: false,
        showMedications: false,
      }
    default:
      return {
        showPatientDemographics: true,
        showEncounterContext: true,
        showEncounterSummaryFields: false,
        showObservations: true,
        showAllergies: false,
        showMedications: false,
      }
  }
}

export function emptyDraft(
  batchType: string,
  overrides: Partial<BatchDraft> = {},
): BatchDraft {
  return {
    batchId: 'b1',
    status: 'IN_ENTRY',
    batchType,
    fieldRequirements: fieldRequirementsForBatchType(batchType),
    ocrConfidence: null,
    patient: null,
    encounter: null,
    observations: [],
    ...overrides,
  }
}
