package medicinemix

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

	emmi "simrs-vx/internal/domain/main-entities/medicine-mix-item"
)

type CreateDto struct {
	Name     string  `json:"name" validate:"maxLength=50"`
	Uom_Code *string `json:"uom_code" validate:"maxLength=10"`
}

type ReadListDto struct {
	Name       string  `json:"name"`
	Uom_Code   *string `json:"uom-code"`
	Pagination ecore.Pagination
}

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

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
	Name     string                  `json:"name"`
	Uom_Code *string                 `json:"uom_code"`
	MixItems []*emmi.MedicineMixItem `json:"mixItems"`
}

func (d MedicineMix) ToResponse() ResponseDto {
	resp := ResponseDto{
		Name:     d.Name,
		Uom_Code: d.Uom_Code,
		MixItems: d.MixItems,
	}
	resp.Main = d.Main
	return resp
}

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