import { type Base, genBase } from './_base'

export interface Soapi extends Base {
  encounter_id: number
  employee_id: number
  time?: string
  typeCode?: string
  value: unknown
}

export function genSoapi(): Soapi {
  return {
    ...genBase(),
    encounter_id: 0,
    employee_id: 0,
    value: '',
  }
}

export interface DiagnosisCode {
  code: string
  name: string
}

export interface AssessmentSection {
  note: string
  codes: DiagnosisCode[]
}

export interface Subject {
  note: string
  'prim-compl': string
  'sec-compl': string
  'pri-complain': string
  'sec-complain': string
  'cur-disea-hist': string
  'pas-disea-hist': string
  'fam-disea-hist': string
  'alg-hist': string
  'alg-react': string
  'med-hist': string
  'blood-type': string
}

export interface ObjectSection {
  note: string
  'consc-level': string
  'consc-level-det': string
  'syst-bp': string
  'diast-bp': string
  pulse: string
  'resp-rate': string
  'hear-rt': string
  'neuro-cranialis': string
  sensoris: string
  'reflect-fisio': string
  'reflect-pato': string
  'autonom-neuron': string
  'neck-rom': string
  'body-rom': string
  'aga-rom': string
  'agb-rom': string
  'neck-mmt': string
  'body-mmt': string
  'aga-mmt': string
  'agb-mmt': string
  localis: string
  'medical-trouble': string
  'rehab-medic-trouble': string
  temp: string
  spo2: string
  weight: string
  height: string
  'head-to-toe': Record<string, string>
}

export interface Assessment {
  'early-diag': AssessmentSection
  'late-diag': AssessmentSection
  'sec-diag': AssessmentSection
}

export interface InstructionCodeGroup {
  note: string
  codes: DiagnosisCode[]
}

export interface Instruction {
  detail: string
  'medical-act': InstructionCodeGroup
  'supporting-exam': DiagnosisCode[]
  therapy: string
  medication: DiagnosisCode[]
  material: DiagnosisCode[]
  'rehab-program': string
  'physic-modal': string
  exercise: string
  'ortes-protesa': string
  education: string
  other: string
}

export interface Soap extends Base {
  subject: Subject
  object: ObjectSection
  assessment: Assessment
  plan: string
  instruction: Instruction
}

// ---- Generators ----

function genDiagnosisCode(): DiagnosisCode {
  return { code: '', name: '' }
}

function genAssessmentSection(): AssessmentSection {
  return { note: '', codes: [genDiagnosisCode()] }
}

export function genSoap(): Soap {
  return {
    ...genBase(),
    subject: {
      note: '',
      'prim-compl': '',
      'sec-compl': '',
      'pri-complain': '',
      'sec-complain': '',
      'cur-disea-hist': '',
      'pas-disea-hist': '',
      'fam-disea-hist': '',
      'alg-hist': '',
      'alg-react': '',
      'med-hist': '',
      'blood-type': '',
    },
    object: {
      note: '',
      'consc-level': '',
      'consc-level-det': '',
      'syst-bp': '',
      'diast-bp': '',
      pulse: '',
      'resp-rate': '',
      'hear-rt': '',
      'neuro-cranialis': '',
      sensoris: '',
      'reflect-fisio': '',
      'reflect-pato': '',
      'autonom-neuron': '',
      'neck-rom': '',
      'body-rom': '',
      'aga-rom': '',
      'agb-rom': '',
      'neck-mmt': '',
      'body-mmt': '',
      'aga-mmt': '',
      'agb-mmt': '',
      localis: '',
      'medical-trouble': '',
      'rehab-medic-trouble': '',
      temp: '',
      spo2: '',
      weight: '',
      height: '',
      'head-to-toe': {},
    },
    assessment: {
      'early-diag': genAssessmentSection(),
      'late-diag': genAssessmentSection(),
      'sec-diag': genAssessmentSection(),
    },
    plan: '',
    instruction: {
      detail: '',
      'medical-act': { note: '', codes: [genDiagnosisCode()] },
      'supporting-exam': [genDiagnosisCode()],
      therapy: '',
      medication: [genDiagnosisCode()],
      material: [genDiagnosisCode()],
      'rehab-program': '',
      'physic-modal': '',
      exercise: '',
      'ortes-protesa': '',
      education: '',
      other: '',
    },
  }
}
