package installation

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	eipb "simrs-vx/internal/domain/main-entities/installation-position/base"

	ere "simrs-vx/internal/domain/references/encounter"
)

type CreateDto struct {
	Id                  *uint                  `json:"id"`
	Code                *string                `json:"code" validate:"maxLength=20"`
	Name                string                 `json:"name" validate:"maxLength=50"`
	EncounterClass_Code ere.EncounterClassCode `json:"encounterClass_code" validate:"maxLength=20"`
}

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"`
	EncounterClass_Code ere.EncounterClassCode `json:"encounterClass-code"`
	Search              string                 `json:"search" gormhelper:"searchColumns=Code,Name"`
}

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

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"`
	EncounterClass_Code   ere.EncounterClassCode `json:"encounterClass_code"`
	InstallationPositions []eipb.Basic           `json:"installationPositions,omitempty"`
}

func (d Installation) ToResponse() ResponseDto {
	resp := ResponseDto{
		Code:                  d.Code,
		Name:                  d.Name,
		EncounterClass_Code:   d.EncounterClass_Code,
		InstallationPositions: d.InstallationPositions,
	}
	resp.SmallMain = d.SmallMain
	return resp
}

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