package itemprice

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

type CreateDto struct {
	Item_Id               *uint   `json:"item_id"`
	Price                 float64 `json:"price"`
	InsuranceCompany_Code *string `json:"insuranceCompany_code" validate:"maxLength=20"`
}

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

type FilterDto struct {
	Item_Id               *uint   `json:"item-id"`
	Price                 float64 `json:"price"`
	InsuranceCompany_Code *string `json:"insuranceCompany-code"`
}
type ReadDetailDto struct {
	Id      uint16 `json:"id"`
	Item_Id *uint  `json:"item_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
	Item_Id               *uint                 `json:"item_id"`
	Item                  *ei.Item              `json:"item,omitempty"`
	Price                 float64               `json:"price"`
	InsuranceCompany_Code *string               `json:"insuranceCompany_code"`
	InsuranceCompany      *eic.InsuranceCompany `json:"insuranceCompany,omitempty"`
}

func (d ItemPrice) ToResponse() ResponseDto {
	resp := ResponseDto{
		Item_Id:               d.Item_Id,
		Item:                  d.Item,
		Price:                 d.Price,
		InsuranceCompany_Code: d.InsuranceCompany_Code,
		InsuranceCompany:      d.InsuranceCompany,
	}
	resp.Main = d.Main
	return resp
}

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