package mcusrccategory

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

	erc "simrs-vx/internal/domain/references/clinical"
)

type CreateDto struct {
	Code       *string          `json:"code" validate:"maxLength=20"`
	Name       string           `json:"name" validate:"maxLength=50"`
	Scope_Code erc.McuScopeCode `json:"scope_code" validate:"maxLength=10"`
}

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"`
	Scope_Code *string `json:"scope-code"`
	Search     string  `json:"search" gormhelper:"searchColumns=Code,Name"`
}

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

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

type DeleteDto struct {
	Id   *uint16 `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.SmallMain
	Code       string           `json:"code"`
	Name       string           `json:"name"`
	Scope_Code erc.McuScopeCode `json:"scope_code"`
}

func (d McuSrcCategory) ToResponse() ResponseDto {
	resp := ResponseDto{
		Code:       d.Code,
		Name:       d.Name,
		Scope_Code: d.Scope_Code,
	}
	resp.SmallMain = d.SmallMain
	return resp
}

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