package medication

import (
	// std
	"time"

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

	// internal - domain - base-entities
	ecore "simrs-vx/internal/domain/base-entities/core"

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

	// internal - domain - main-entities
	ee "simrs-vx/internal/domain/main-entities/encounter"
	ep "simrs-vx/internal/domain/main-entities/pharmacist"
)

type CreateDto struct {
	Encounter_Id    *uint              `json:"encounter_id"`
	IssuedAt        *time.Time         `json:"issuedAt"`
	Pharmacist_Code *string            `json:"pharmacist_code"`
	Status_Code     erc.DataStatusCode `json:"status_code"`
}

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

type FilterDto struct {
	Encounter_Id    *uint              `json:"encounter-id"`
	IssuedAt        *time.Time         `json:"issuedAt"`
	Pharmacist_Code *string            `json:"pharmacist-code"`
	Status_Code     erc.DataStatusCode `json:"status-code"`
}
type ReadDetailDto struct {
	Id           uint  `json:"id"`
	Encounter_Id *uint `json:"encounter_id"`

	pa.AuthInfo
}

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"`
	Encounter       *ee.Encounter      `json:"encounter,omitempty"`
	IssuedAt        *time.Time         `json:"issuedAt"`
	Pharmacist_Code *string            `json:"pharmacist_code"`
	Pharmacist      *ep.Pharmacist     `json:"pharmacist,omitempty"`
	Status_Code     erc.DataStatusCode `json:"status_code"`
}

func (d Medication) ToResponse() ResponseDto {
	resp := ResponseDto{
		Encounter_Id:    d.Encounter_Id,
		Encounter:       d.Encounter,
		IssuedAt:        d.IssuedAt,
		Pharmacist_Code: d.Pharmacist_Code,
		Pharmacist:      d.Pharmacist,
		Status_Code:     d.Status_Code,
	}
	resp.Main = d.Main
	return resp
}

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