package materialpackage

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	em "simrs-vx/internal/domain/main-entities/material"
	emp "simrs-vx/internal/domain/main-entities/material-package"
)

type CreateDto struct {
	MaterialPackage_Code string `json:"materialPackage_code" validate:"maxLength=20"`
	Material_Code        string `json:"material_code" validate:"maxLength=20"`
	Count                uint16 `json:"count" validate:"required"`
}

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

type FilterDto struct {
	MaterialPackage_Code string `json:"material-package-code"`
	Material_Code        string `json:"material_code"`
}

type ReadDetailDto struct {
	Id uint `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
	MaterialPackage_Code string               `json:"materialPackage_code"`
	MaterialPackage      *emp.MaterialPackage `json:"materialPackage,omitempty"`
	Material_Code        string               `json:"material_code"`
	Material             *em.Material         `json:"material,omitempty"`
	Count                *uint16              `json:"count"`
}

func (d MaterialPackageItem) ToResponse() ResponseDto {
	resp := ResponseDto{
		MaterialPackage_Code: d.MaterialPackage_Code,
		MaterialPackage:      d.MaterialPackage,
		Material_Code:        d.Material_Code,
		Material:             d.Material,
		Count:                d.Count,
	}
	resp.Id = d.Id
	return resp
}

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