package regency

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	edb "simrs-vx/internal/domain/main-entities/district/base"
	ep "simrs-vx/internal/domain/main-entities/province"
	erb "simrs-vx/internal/domain/main-entities/regency/base"
)

type CreateDto struct {
	Province_Code string  `json:"province_code" validate:"numeric;maxLength=2"`
	Code          *string `json:"code" validate:"numeric;maxLength=4"`
	Name          string  `json:"name" validate:"alphaSpace;maxLength=50"`
}

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

type FilterDto struct {
	Province_Code string `json:"province-code"`
	Code          string `json:"code"`
	Name          string `json:"name"`
	Search        string `json:"search" gormhelper:"searchColumns=Code,Name"`
}

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

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 {
	erb.Basic
	Province  *ep.Province `json:"province,omitempty"`
	Districts []*edb.Basic `json:"districts,omitempty"`
}

func (d Regency) ToResponse() ResponseDto {
	resp := ResponseDto{
		Basic:     d.Basic,
		Province:  d.Province,
		Districts: d.Districts,
	}
	return resp
}

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