package internal_reference

import (
	erc "simrs-vx/internal/domain/references/common"

	ecore "simrs-vx/internal/domain/base-entities/core"
	ed "simrs-vx/internal/domain/main-entities/doctor"
	eu "simrs-vx/internal/domain/main-entities/unit"
)

type CreateDto struct {
	Encounter_Id   *uint                `json:"-"`
	Unit_Code      *string              `json:"unit_code"`
	Doctor_Code    *string              `json:"doctor_code"`
	Nurse_Code     *string              `json:"nurse_code"`
	Status_Code    erc.DataApprovalCode `json:"status_code"`
	SrcDoctor_Code *string              `json:"srcDoctor_code"`
	SrcNurse_Code  *string              `json:"srcNurse_code"`
}

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

type FilterDto struct {
	Encounter_Id *uint                `json:"encounter-id"`
	Unit_Code    *uint                `json:"unit-code"`
	Doctor_Code  *uint                `json:"doctor-code"`
	Status_Code  erc.DataApprovalCode `json:"status-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 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"`
	Unit_Code    *string               `json:"unit_code"`
	Unit         *eu.Unit              `json:"unit,omitempty"`
	Doctor_Code  *string               `json:"doctor_id"`
	Doctor       *ed.Doctor            `json:"doctor,omitempty"`
	Status_Code  *erc.DataApprovalCode `json:"status_code"`
}

func (d InternalReference) ToResponse() ResponseDto {
	resp := ResponseDto{
		Encounter_Id: d.Encounter_Id,
		Unit_Code:    d.Unit_Code,
		Unit:         d.Unit,
		Doctor_Code:  d.Doctor_Code,
		Doctor:       d.Doctor,
		Status_Code:  d.Status_Code,
	}
	resp.Main = d.Main
	return resp
}

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