import { z } from 'zod'
import type { Soap } from '~/models/soapi'

const DiagnosisCodeSchema = z.object({
  code: z.string().default(''),
  name: z.string().default(''),
})

const AssessmentSectionSchema = z.object({
  note: z.string().default(''),
  codes: z.array(DiagnosisCodeSchema).default([]),
})

export const EarlySchema = z.object({
  'prim-compl': z.string({ required_error: 'Keluhan utama harus diisi' }).min(1, 'Keluhan utama harus diisi'),
  'cur-disea-hist': z.string().default(''),
  'syst-bp': z.string().default(''),
  'diast-bp': z.string().default(''),
  pulse: z.string().default(''),
  'resp-rate': z.string().default(''),
  temp: z.string().default(''),
  weight: z.string().default(''),
  height: z.string().default(''),
  'reflect-fisio': z.string().default(''),
  'reflect-pato': z.string().default(''),
  'autonom-neuron': z.string().default(''),
  'medical-act': z.string().default(''),
  therapy: z.string().default(''),
})

export const EarlyRehabSchema = z.object({
  'prim-compl': z.string({ required_error: 'Keluhan utama harus diisi' }).min(1, 'Keluhan utama harus diisi'),
  'medical-plan': z.string().default(''),
  'diagnosis-medical': z.string().default(''),
  'rehab-trouble': z.string().default(''),
  'medical-trouble': z.string().default(''),
  'physic-modal': z.string().default(''),
  exercise: z.string().default(''),
  'ortho-pesa': z.string().default(''),
  education: z.string().default(''),
  other: z.string().default(''),
  cranialis: z.string().default(''),
  sensoris: z.string().default(''),
  'reflect-fisio': z.string().default(''),
  'reflect-pato': z.string().default(''),
  otonom: z.string().default(''),
  localis: z.string().default(''),
  'medical-trial': z.string().default(''),
  therapy: z.string().default(''),
  'syst-bp': z.string().default(''),
  'diast-bp': z.string().default(''),
  pulse: z.string().default(''),
  gcs: z.string().default(''),
  'respiratory-rate': z.string().default(''),
  temp: z.string().default(''),
  weight: z.string().default(''),
  height: z.string().default(''),
  ambulance: z.string().default(''),
  gait: z.string().default(''),
  'neck-rom': z.string().default(''),
  'body-rom': z.string().default(''),
  'aga-rom': z.string().default(''),
  'agb-rom': z.string().default(''),
  'neck-mmt': z.string().default(''),
  'body-mmt': z.string().default(''),
  'aga-mmt': z.string().default(''),
  'agb-mmt': z.string().default(''),
})

export const FunctionSoapiSchema = z.object({
  'prim-compl': z.string({ required_error: 'Keluhan utama harus diisi' }).min(1, 'Keluhan utama harus diisi'),
  'past-disease': z.string().default(''),
  'current-disease': z.string().default(''),
  gcs: z.string().default(''),
  'respiratory-rate': z.string().default(''),
  'respiratory-rate-type': z.string().default(''),
  pulse: z.string().default(''),
  'pulse-type': z.string().default(''),
  'right-arm-bp': z.string().default(''),
  'left-arm-bp': z.string().default(''),
  'axillary-temp': z.string().default(''),
  'rektal-temp': z.string().default(''),
  skin: z.string().default(''),
  head: z.string().default(''),
  ear: z.string().default(''),
  nose: z.string().default(''),
  'oral-cavity': z.string().default(''),
  eye: z.string().default(''),
  'other-body-part': z.string().default(''),
  neck: z.string().default(''),
  thyroid: z.string().default(''),
  thorax: z.string().default(''),
  heart: z.string().default(''),
  lung: z.string().default(''),
  abdomen: z.string().default(''),
  heart2: z.string().default(''),
  lien: z.string().default(''),
  back: z.string().default(''),
  extremity: z.string().default(''),
  gender: z.string().default(''),
  rectum: z.string().default(''),
  'system-syaraf': z.string().default(''),
  'nervous-system': z.string().default(''),
  'cardio-respiratory': z.string().default(''),
  imaging: z.string().default(''),
  laboratory: z.string().default(''),
})

export const SubjectSchema = z.object({
  note: z.string().default(''),
  'prim-compl': z.string({ required_error: 'Keluhan utama harus diisi' }).min(1, 'Keluhan utama harus diisi'),
  'sec-compl': z.string().default(''),
  'pri-complain': z.string().default(''),
  'sec-complain': z.string().default(''),
  'cur-disea-hist': z.string().default(''),
  'pas-disea-hist': z.string().default(''),
  'fam-disea-hist': z.string().default(''),
  'alg-hist': z.string().default(''),
  'alg-react': z.string().default(''),
  'med-hist': z.string().default(''),
  'blood-type': z.string().default(''),
})

export const ObjectSchema = z.object({
  note: z.string().default(''),
  'consc-level': z.string().default(''),
  'consc-level-det': z.string().default(''),
  'syst-bp': z.string().default(''),
  'diast-bp': z.string().default(''),
  pulse: z.string().default(''),
  'resp-rate': z.string().default(''),
  'hear-rt': z.string().default(''),
  'neuro-cranialis': z.string().default(''),
  sensoris: z.string().default(''),
  'reflect-fisio': z.string().default(''),
  'reflect-pato': z.string().default(''),
  'autonom-neuron': z.string().default(''),
  'neck-rom': z.string().default(''),
  'body-rom': z.string().default(''),
  'aga-rom': z.string().default(''),
  'agb-rom': z.string().default(''),
  'neck-mmt': z.string().default(''),
  'body-mmt': z.string().default(''),
  'aga-mmt': z.string().default(''),
  'agb-mmt': z.string().default(''),
  localis: z.string().default(''),
  'medical-trouble': z.string().default(''),
  'rehab-medic-trouble': z.string().default(''),
  temp: z.string().default(''),
  spo2: z.string().default(''),
  weight: z.string().default(''),
  height: z.string().default(''),
  'head-to-toe': z.record(z.string()).default({}),
})

const AssessmentSchema = z.object({
  'early-diag': AssessmentSectionSchema,
  'late-diag': AssessmentSectionSchema,
  'sec-diag': AssessmentSectionSchema,
})

const InstructionCodeGroupSchema = z.object({
  note: z.string().default(''),
  codes: z.array(DiagnosisCodeSchema).default([]),
})

const InstructionSchema = z.object({
  detail: z.string().default(''),
  'medical-act': InstructionCodeGroupSchema,
  'supporting-exam': z.array(DiagnosisCodeSchema).default([]),
  therapy: z.string().default(''),
  medication: z.array(DiagnosisCodeSchema).default([]),
  material: z.array(DiagnosisCodeSchema).default([]),
  'rehab-program': z.string().default(''),
  'physic-modal': z.string().default(''),
  exercise: z.string().default(''),
  'ortes-protesa': z.string().default(''),
  education: z.string().default(''),
  other: z.string().default(''),
})

export const SoapSchema = z.object({
  subject: SubjectSchema,
  object: ObjectSchema,
  assessment: AssessmentSchema,
  plan: z.string().default(''),
  instruction: InstructionSchema,
})

export type SoapiFormData = z.infer<typeof SoapSchema> & Partial<Soap>
