package radiologymcuorder

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"
	ermoi "simrs-vx/internal/domain/main-entities/radiology-mcu-order-item/base"
)

type CreateDto struct {
	Encounter_Id  uint                 `json:"encounter_id"`
	Number        *uint64              `json:"number"` // SHOULD BE AUTOMATIC WITHOUT SYNC
	Doctor_Code   string               `json:"-" validate:"required"`
	ClinicalNotes *string              `json:"clinicalNotes"`
	OtherNotes    *string              `json:"otherNotes"`
	Items         []ermoi.SubCreateDto `json:"items" validate:"required"`
	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 `json:"encounter_id"`
	Encounter     *ee.Encounter
	Number        uint64 `json:"number"`
	Doctor_Code   string `json:"doctor_code"`
	Doctor        *ed.Doctor
	ClinicalNotes *string `json:"clinicalNotes"`
	OtherNotes    *string `json:"otherNotes"`
	Resume        *string `json:"resume"`
	Items         []*ermoi.RadiologyMcuOrderItem
}

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

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