import { z } from 'zod'

const TherapyProtocolSchema = z.object({
  examinationDate: z.string({
    required_error: 'Pilih tanggal pemeriksaan',
  }),
  relationshipToInsured: z.enum(['spouse', 'child'], {
    required_error: 'Pilih hubungan',
  }),
  anamnesis: z.string({
    required_error: 'Mohon lengkapi catatan anamnesa',
  }),
  medicalHistory: z.string({
    required_error: 'Mohon lengkapi catatan riwayat penyakit',
  }),
  medicationHistory: z.string({
    required_error: 'Mohon lengkapi catatan riwayat obat',
  }),

  supportDiagnosis: z.array(
    z.object({
      diagnosis: z.string({
        required_error: 'Isi diagnosis',
      }),
    }),
    {
      required_error: 'Isi diagnosis',
    },
  ),
  functionalDiagnosis: z.array(
    z
      .object({
        diagnosis: z.string({}),
      })
      .optional(),
    {
      required_error: 'Isi diagnosis',
    },
  ),
  treatmentDiagnosis: z.array(
    z.object({
      diagnosis: z.string({
        required_error: 'Isi diagnosis',
      }),
    }),
    {
      required_error: 'Isi diagnosis',
    },
  ),
  supportExamination: z.string({
    required_error: 'Mohon lengkapi catatan pemeriksaan penunjang',
  }),

  recommendation: z.string({
    required_error: 'Mohon lengkapi catatan anjuran',
  }),
  evaluation: z.string({
    required_error: 'Mohon lengkapi catatan evaluasi',
  }),
  isWorkRelatedDisease: z.string({
    required_error: 'Pilih apakah penyakit berkaitan dengan pekerjaan',
  }),
})



const PickerItemSchema = z.object({
  id: z.number().optional(),
  code: z.string(),
  name: z.string()
})

const TherapyProtocolMedicRehabilitationSchema = z.object({
  form1ExaminationDate: z.string({
    required_error: 'Pilih tanggal pemeriksaan',
  }),
  form1Diagnose: z.string({
    required_error: 'Mohon lengkapi catatan diagnosa',
  }),
  form1TherapyRequest: z.string({
    required_error: 'Mohon lengkapi catatan terapi',
  }),
  form1TargetPeriod: z.number({
    required_error: 'Mohon lengkapi catatan terapi',
  }),
  form1TherapyTarget: z.string({
    required_error: 'Mohon lengkapi catatan terapi',
  }),

  form2RelationshipToInsured: z.enum(['spouse', 'child'], {
    required_error: 'Pilih hubungan',
  }),
  anamnesis: z.string({
    required_error: 'Mohon lengkapi catatan anamnesa',
  }),
  form2PhysicalExamination: z.string({
    required_error: 'Mohon lengkapi catatan pemeriksaan fisik',
  }),

  medicalDiagnoses: z.array(PickerItemSchema).default([]),
  functionDiagnoses: z.array(PickerItemSchema).default([]),
  procedures: z.array(PickerItemSchema).default([]),

  supportingExams: z.string({
    required_error: 'Mohon lengkapi catatan pemeriksaan penunjang',
  }),
  evaluation: z.string({
    required_error: 'Mohon lengkapi catatan evaluasi',
  }),
  instruction: z.string({
    required_error: 'Mohon lengkapi catatan anjuran',
  }),
  workCauseStatus: z.enum(['YA', 'TIDAK'], {
    required_error: 'Pilih apakah penyakit berkaitan dengan pekerjaan',
  }),

  form3ExaminationDate: z.string({
    required_error: 'Pilih tanggal pemeriksaan',
  }),
  form3Diagnose: z.string({
    required_error: 'Mohon lengkapi catatan diagnosa',
  }),
  form3TherapyRequest: z.string({
    required_error: 'Mohon lengkapi catatan terapi',
  }),
  form3ProgramActivities: z.array(
    z.string({
      required_error: 'Mohon lengkapi Program/Kegiatan',
    }),
    {
      required_error: 'Isi Program/Kegiatan',
    },
  ).default(['']),
})


// {
//     "encounter_id": 4,
//     "doctor_code": "doc-3",
//     "anamnesis": "",
//     "medicalDiagnoses": "", //json
//     "functionDiagnoses": "", //json
//     "procedures":"", 
//     "supportingExams":"",
//     "instruction":"",
//     "evaluation":"",
//     "workCauseStatus":"YA",
//     "frequency":1,
//     "intervalUnit_code":"day",
//     "duration":30,
//     "durationUnit_code":"min"
// }


type TherapyProtocolFormData = z.infer<typeof TherapyProtocolSchema>
type TherapyProtocolMedicRehabilitationFormData = z.infer<typeof TherapyProtocolMedicRehabilitationSchema>

export { TherapyProtocolSchema, TherapyProtocolMedicRehabilitationSchema }
export type { TherapyProtocolFormData, TherapyProtocolMedicRehabilitationFormData }
