package chemo

import (
	// std
	"time"

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

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

	// internal - domain - main-entities
	ecore "simrs-vx/internal/domain/base-entities/core"
	ee "simrs-vx/internal/domain/main-entities/encounter"
	eun "simrs-vx/internal/domain/main-entities/unit"
	eus "simrs-vx/internal/domain/main-entities/user"
)

type CreateDto struct {
	Encounter_Id *uint                `json:"encounter_id"`
	Status_Code  erc.DataVerifiedCode `json:"status_code"`
	SrcUnit_Code *string              `json:"srcUnit_code"`
}

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

type FilterDto struct {
	Encounter_Id       *uint                 `json:"encounter-id"`
	Status_Code        *erc.DataVerifiedCode `json:"status-code"`
	VerifiedBy_User_Id *uint                 `json:"verifiedBy-user-id"`
	SrcUnit_Code       *string               `json:"srcUnit-code"`
}

type ReadDetailDto struct {
	Id uint16 `json:"id"`
}

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

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

type VerifyDto struct {
	Id          uint16               `json:"id"`
	Status_Code erc.DataVerifiedCode `json:"status_code"`
	Bed         *string              `json:"bed" validate:"required"`
	Needs       *string              `json:"needs" validate:"required"`

	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"`
	Status_Code        erc.DataVerifiedCode `json:"status_code"`
	VerifiedAt         *time.Time           `json:"verifiedAt"`
	VerifiedBy_User_Id *uint                `json:"verifiedBy_user_id"`
	VerifiedBy         *eus.User            `json:"verifiedBy,omitempty"`
	SrcUnit_Code       *string              `json:"srcUnit_code"`
	SrcUnit            *eun.Unit            `json:"srcUnit,omitempty"`
}

func (d Chemo) ToResponse() ResponseDto {
	resp := ResponseDto{
		Encounter_Id:       d.Encounter_Id,
		Encounter:          d.Encounter,
		Status_Code:        d.Status_Code,
		VerifiedAt:         d.VerifiedAt,
		VerifiedBy_User_Id: d.VerifiedBy_User_Id,
		VerifiedBy:         d.VerifiedBy,
		SrcUnit_Code:       d.SrcUnit_Code,
		SrcUnit:            d.SrcUnit,
	}
	resp.Main = d.Main
	return resp
}

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