package medicalactionsrc

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	ei "simrs-vx/internal/domain/main-entities/item"
)

type CreateDto struct {
	Code      *string `json:"code" validate:"maxLength=20"`
	Name      string  `json:"name" validate:"maxLength=50"`
	Type_Code string  `json:"type_code" validate:"maxLength=20"`
	Item_Code *string `json:"item_code"`
}

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

type FilterDto struct {
	Code      *string `json:"code"`
	Name      string  `json:"name"`
	Type_Code string  `json:"type_code"`
	Item_Code *string `json:"item-code"`
	Search    string  `json:"search" gormhelper:"searchColumns=Code,Name"`
}

type ReadDetailDto struct {
	Id   *uint16 `json:"id"`
	Code *string `json:"code"`
}

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

type DeleteDto struct {
	Id   *uint   `json:"id"`
	Code *string `json:"code"`
}

type MetaDto struct {
	PageNumber int `json:"page_number"`
	PageSize   int `json:"page_size"`
	Count      int `json:"count"`
}

type ResponseDto struct {
	ecore.Main
	Code      string   `json:"code"`
	Name      string   `json:"name"`
	Type_Code string   `json:"type_code"`
	Item_Code *string  `json:"item_code"`
	Item      *ei.Item `json:"item,omitempty"`
}

func (d MedicalActionSrc) ToResponse() ResponseDto {
	resp := ResponseDto{
		Code:      d.Code,
		Name:      d.Name,
		Type_Code: d.Type_Code,
		Item_Code: d.Item_Code,
		Item:      d.Item,
	}
	resp.Main = d.Main
	return resp
}

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