package micromcuorder

import (
	la "simrs-vx/internal/lib/auth"

	ecore "simrs-vx/internal/domain/base-entities/core"
	ed "simrs-vx/internal/domain/main-entities/doctor"
	ee "simrs-vx/internal/domain/main-entities/encounter"
	ercl "simrs-vx/internal/domain/references/clinical"
)

type CreateDto struct {
	Encounter_Id    uint    `json:"encounter_id" validate:"required"`
	Number          uint64  `json:"number"` // SHOULD BE AUTOMATIC WITHOUT SYNC
	OrderStage_Code string  `json:"orderStage_code" gorm:"not null;size:10"`
	AxillaryTemp    float64 `json:"axillaryTemp"`
	OtherNotes      string  `json:"otherNotes"`
	la.AuthInfo
}

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

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

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

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

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

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

type ResponseDto struct {
	ecore.BigMain
	Encounter_Id uint
	Encounter    *ee.Encounter
	Number       uint64 `json:"number"`
	Doctor_Code  string `json:"doctor_code"`
	Doctor       *ed.Doctor
	Stage_Code   ercl.McuOrderStageCode `json:"stage_code" gorm:"not null;size:10"`
	AxillaryTemp float64                `json:"axillaryTemp"`
	OtherNotes   *string                `json:"otherNotes"`
}

func (d MicroMcuOrder) ToResponse() ResponseDto {
	resp := ResponseDto{
		Encounter_Id: d.Encounter_Id,
		Encounter:    d.Encounter,
		Number:       d.Number,
		Doctor_Code:  d.Doctor_Code,
		Doctor:       d.Doctor,
		Stage_Code:   d.Stage_Code,
		AxillaryTemp: d.AxillaryTemp,
		OtherNotes:   d.OtherNotes,
	}
	resp.BigMain = d.BigMain
	return resp
}

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