package procedureroom

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	ei "simrs-vx/internal/domain/main-entities/infra"
	es "simrs-vx/internal/domain/main-entities/specialist"
	ess "simrs-vx/internal/domain/main-entities/subspecialist"
	eu "simrs-vx/internal/domain/main-entities/unit"
)

type CreateDto struct {
	Code               *string `json:"code"`
	Infra_Code         *string `json:"infra_code"`
	Type_Code          string  `json:"type_code"`
	Unit_Code          *string `json:"unit_code"`
	Specialist_Code    *string `json:"specialist_code"`
	Subspecialist_Code *string `json:"subspecialist_code"`
}

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

type FilterDto struct {
	Infra_Code         *string `json:"infra-code"`
	Type_Code          string  `json:"type-code"`
	Unit_Code          *string `json:"unit-code"`
	Specialist_Code    *string `json:"specialist-code"`
	Subspecialist_Code *string `json:"subspecialist-code"`
}

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.SmallMain
	Code               string             `json:"code"`
	Type_Code          *string            `json:"type_code"`
	Infra_Code         *string            `json:"infra_code"`
	Infra              *ei.Infra          `json:"infra,omitempty"`
	Unit_Code          *string            `json:"unit_code"`
	Unit               *eu.Unit           `json:"unit,omitempty"`
	Specialist_Code    *string            `json:"specialist_code"`
	Specialist         *es.Specialist     `json:"specialist,omitempty"`
	Subspecialist_Code *string            `json:"subspecialist_code"`
	Subspecialist      *ess.Subspecialist `json:"subspecialist,omitempty"`
}

func (d ProcedureRoom) ToResponse() ResponseDto {
	resp := ResponseDto{
		Code:               d.Code,
		Infra_Code:         d.Infra_Code,
		Infra:              d.Infra,
		Type_Code:          (*string)(d.Type_Code),
		Unit_Code:          d.Unit_Code,
		Unit:               d.Unit,
		Specialist_Code:    d.Specialist_Code,
		Specialist:         d.Specialist,
		Subspecialist_Code: d.Subspecialist_Code,
		Subspecialist:      d.Subspecialist,
	}
	resp.SmallMain = d.SmallMain
	return resp
}

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