import { type DiagnosisReportVO, fromDiagnosisReport, type PatientVO } from '@/model/diagnosis-report.model';

export interface FollowUpEvaluationReportDTO {
  id: string;

  patientId: string;
  patientName: string;
  sex: '1' | '2';
  age: string | number;
  phone: string;
  tagNames: string;

  followupPlanName: string;

  progress: '0' | '1' | '2';
  evaluateProgress: '0' | '1';
  evaluateDeal: '1' | '2';
  evaluateBy: string;

  evaluate?: {
    evaluateDeal: '1' | '2';
  }
}

export interface FollowUpEvaluationReportVO {
  id: string;
  plan: {
    name: string;
  };
  followUp: {
    status: string | { value: '0' | '1' | '2'; label: string };
  };
  evaluation: {
    status: string | { value: '0' | '1'; label: string };
    result: string | { value: '1' | '2'; label: string };
    operator: {
      name: string;
    };
  };
  patient: PatientVO;
  diagnosis: DiagnosisReportVO;
  tags: string;

  __origin__?: FollowUpEvaluationReportDTO;
}

export function fromFollowUpEvaluationReport({ id, ...data }: FollowUpEvaluationReportDTO): FollowUpEvaluationReportVO {
  Object.assign(data, data.evaluate)
  return {
    id,
    diagnosis: fromDiagnosisReport(data as any),
    patient: {
      id: data.patientId,
      name: data.patientName,
      gender: data.sex as PatientVO['gender'],
      age: data.age,
      phone: data.phone,
    },
    tags: data.tagNames,
    plan: {
      name: data.followupPlanName,
    },
    evaluation: {
      status: { value: data.evaluateProgress, label: { 0: '未完成', 1: '已完成' }[data.evaluateProgress] },
      result: { value: data.evaluateDeal, label: { 1: '复诊', 2: '中医调养' }[data.evaluateDeal] },
      operator: { name: data.evaluateBy },
    },
    followUp: {
      status: { value: data.progress, label: { 0: '未开始', 1: '未完成', 2: '已完成' }[data.progress] },
    },

    __origin__: { id, ...data },
  };
}
