package therapy_protocol

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	ed "simrs-vx/internal/domain/main-entities/doctor"
	ee "simrs-vx/internal/domain/main-entities/encounter"
	erc "simrs-vx/internal/domain/references/common"

	pa "simrs-vx/internal/lib/auth"
)

type CreateDto struct {
	Encounter_Id      *uint                 `json:"encounter_id"`
	Doctor_Code       *string               `json:"doctor_code"`
	Anamnesis         *string               `json:"anamnesis" validate:"maxLength=2048"`
	MedicalDiagnoses  *string               `json:"medicalDiagnoses"`
	FunctionDiagnoses *string               `json:"functionDiagnoses"`
	Procedures        *string               `json:"procedures"`
	SupportingExams   *string               `json:"supportingExams" validate:"maxLength=2048"`
	Instruction       *string               `json:"instruction" validate:"maxLength=2048"`
	Evaluation        *string               `json:"evaluation" validate:"maxLength=2048"`
	WorkCauseStatus   *string               `json:"workCauseStatus"`
	Frequency         *uint                 `json:"frequency"`
	IntervalUnit_Code *erc.TimeUnitCode     `json:"intervalUnit_code" validate:"maxLength=10"`
	Duration          *uint                 `json:"duration"`
	DurationUnit_Code *erc.TimeUnitCode     `json:"durationUnit_code" validate:"maxLength=10"`
	Status_Code       *erc.DataVerifiedCode `json:"status_code"`
}

type ReadListDto struct {
	FilterDto
	Includes   string `json:"includes"`
	Pagination ecore.Pagination
}

type FilterDto struct {
	Encounter_Id *uint   `json:"encounter-id"`
	Doctor_Code  *string `json:"doctor-code"`
}

type ReadDetailDto struct {
	Id       uint   `json:"id"`
	Includes string `json:"includes"`
}

type UpdateDto struct {
	Id uint `json:"id"`
	CreateDto
}

type DeleteDto struct {
	Id uint `json:"id"`
}

type VerifyDto struct {
	Id          uint                 `json:"id"`
	Status_Code erc.DataVerifiedCode `json:"status_code"`

	pa.AuthInfo
}

type MetaDto struct {
	PageNumber int `json:"page_number"`
	PageSize   int `json:"page_size"`
	Count      int `json:"count"`
}

type ResponseDto struct {
	ecore.Main
	Encounter_Id      *uint                 `json:"encounter_id"`
	Encounter         *ee.Encounter         `json:"encounter,omitempty"`
	Doctor_Code       *string               `json:"doctor_code"`
	Doctor            *ed.Doctor            `json:"doctor,omitempty"`
	Anamnesis         *string               `json:"anamnesis"`
	MedicalDiagnoses  *string               `json:"medicalDiagnoses"`
	FunctionDiagnoses *string               `json:"functionDiagnoses"`
	Procedures        *string               `json:"procedures"`
	SupportingExams   *string               `json:"supportingExams"`
	Instruction       *string               `json:"instruction"`
	Evaluation        *string               `json:"evaluation"`
	WorkCauseStatus   *string               `json:"workCauseStatus"`
	Frequency         *uint                 `json:"frequency"`
	IntervalUnit_Code *erc.TimeUnitCode     `json:"intervalUnit_code"`
	Duration          *uint                 `json:"duration"`
	DurationUnit_Code *erc.TimeUnitCode     `json:"durationUnit_code"`
	Status_Code       *erc.DataVerifiedCode `json:"status_code"`
}

func (d TherapyProtocol) ToResponse() ResponseDto {
	resp := ResponseDto{
		Encounter_Id:      d.Encounter_Id,
		Encounter:         d.Encounter,
		Doctor_Code:       d.Doctor_Code,
		Doctor:            d.Doctor,
		Anamnesis:         d.Anamnesis,
		MedicalDiagnoses:  d.MedicalDiagnoses,
		FunctionDiagnoses: d.FunctionDiagnoses,
		Procedures:        d.Procedures,
		SupportingExams:   d.SupportingExams,
		Instruction:       d.Instruction,
		Evaluation:        d.Evaluation,
		WorkCauseStatus:   d.WorkCauseStatus,
		Frequency:         d.Frequency,
		IntervalUnit_Code: d.IntervalUnit_Code,
		Duration:          d.Duration,
		DurationUnit_Code: d.DurationUnit_Code,
		Status_Code:       d.Status_Code,
	}
	resp.Main = d.Main
	return resp
}

func ToResponseList(data []TherapyProtocol) []ResponseDto {
	resp := make([]ResponseDto, len(data))
	for i, u := range data {
		resp[i] = u.ToResponse()
	}
	return resp
}
