package antibioticsrc

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"`
	AntibioticSrcCategory_Code *string `json:"antibioticSrcCategory_code" validate:"maxLength=20"`
	Item_Id                    *uint   `json:"item_id"`
}

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"`
	AntibioticSrcCategory_Code *string `json:"antibiotic-src-category-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"`
}

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"`
	AntibioticSrcCategory_Code *string  `json:"antibioticSrcCategory_code"`
	Item_Id                    *uint    `json:"item_id"`
	Item                       *ei.Item `json:"item,omitempty"`
}

func (d AntibioticSrc) ToResponse() ResponseDto {
	resp := ResponseDto{
		Code:                       d.Code,
		Name:                       d.Name,
		AntibioticSrcCategory_Code: d.AntibioticSrcCategory_Code,
		// Item_Id:                    d.Item_Id,
		// Item:                       d.Item,
	}
	resp.Main = d.Main
	return resp
}

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