package cpmcuorder

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"
)

type CreateDto struct {
	Encounter_Id      uint   `json:"encounter_id" validate:"required"`
	Number            uint64 `json:"number"` // SHOULD BE AUTOMATIC WITHOUT SYNC
	UrgencyLevel_Code string `json:"urgencyLevel_code" validate:"required"`
	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
	UrgencyLevel_Code string  `json:"urgencyLevel_code" gorm:"not null;size:15"`
	OtherNotes        *string `json:"otherNotes"`
	Resume            *string `json:"resume"`
}

func (d CpMcuOrder) ToResponse() ResponseDto {
	resp := ResponseDto{
		Encounter_Id:      d.Encounter_Id,
		Encounter:         d.Encounter,
		Number:            d.Number,
		Doctor_Code:       d.Doctor_Code,
		Doctor:            d.Doctor,
		UrgencyLevel_Code: string(d.UrgencyLevel_Code),
		OtherNotes:        d.OtherNotes,
		Resume:            d.Resume,
	}
	resp.BigMain = d.BigMain
	return resp
}

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