package subspecialist

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

type CreateDto struct {
	Id              *uint   `json:"id"`
	Code            string  `json:"code" validate:"maxLength=20"`
	Name            string  `json:"name" validate:"maxLength=50"`
	Specialist_Code *string `json:"specialist_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"`
	Specialist_Code *string `json:"specialist-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"`
	Specialist_Code *string        `json:"specialist_code"`
	Specialist      *es.Specialist `json:"specialist,omitempty"`
	Subspecialist   []espb.Basic   `json:"subspecialistPositions,omitempty"`
}

func (d Subspecialist) ToResponse() ResponseDto {
	resp := ResponseDto{
		Code:            d.Code,
		Name:            d.Name,
		Specialist_Code: d.Specialist_Code,
		Specialist:      d.Specialist,
		Subspecialist:   d.SubspecialistPositions,
	}
	resp.SmallMain = d.SmallMain
	return resp
}

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