package specialist

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	espb "simrs-vx/internal/domain/main-entities/specialist-position/base"
	essb "simrs-vx/internal/domain/main-entities/subspecialist/base"
	eu "simrs-vx/internal/domain/main-entities/unit"
)

type CreateDto struct {
	Id        *uint   `json:"id"`
	Code      string  `json:"code" validate:"maxLength=10"`
	Name      string  `json:"name" validate:"maxLength=50"`
	Unit_Code *string `json:"unit_code"`
}

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"`
	Unit_Code *string `json:"unit-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"`
	Unit_Code           *string      `json:"unit_code"`
	Unit                *eu.Unit     `json:"unit,omitempty"`
	SpecialistPositions []espb.Basic `json:"specialistPositions,omitempty"`
	Subspecialists      []essb.Basic `json:"subspecialists,omitempty"`
}

func (d Specialist) ToResponse() ResponseDto {
	resp := ResponseDto{
		Code:                d.Code,
		Name:                d.Name,
		Unit:                d.Unit,
		Unit_Code:           d.Unit_Code,
		SpecialistPositions: d.SpecialistPositions,
		Subspecialists:      d.Subspecialists,
	}
	resp.SmallMain = d.SmallMain
	return resp
}

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