package materialorderitem

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

type CreateDto struct {
	MaterialOrder_Id *uint   `json:"materialOrder_id"`
	Material_Code    *string `json:"material_code"`
	Count            *uint16 `json:"count"`
}

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

type FilterDto struct {
	MaterialOrder_Id *uint   `json:"materialOrder-id"`
	Material_Code    *string `json:"material-code"`
	Count            *uint16 `json:"count"`
}
type ReadDetailDto struct {
	Id uint16 `json:"id"`
}

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
	MaterialOrder_Id *uint              `json:"materialOrder_id"`
	MaterialOrder    *emo.MaterialOrder `json:"materialOrder,omitempty"`
	Material_Code    *string            `json:"material_code"`
	Material         *em.Material       `json:"material,omitempty"`
	Count            *uint16            `json:"count"`
}

func (d MaterialOrderItem) ToResponse() ResponseDto {
	resp := ResponseDto{
		MaterialOrder_Id: d.MaterialOrder_Id,
		MaterialOrder:    d.MaterialOrder,
		Material_Code:    d.Material_Code,
		Material:         d.Material,
		Count:            d.Count,
	}
	resp.Main = d.Main
	return resp
}

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