package province

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

type CreateDto struct {
	Code *string `json:"code" validate:"required;minLength=2;maxLength=2"`
	Name string  `json:"name" validate:"required;maxLength=10"`
}

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"`
	Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
}

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

type UpdateDto struct {
	Id *int16 `json:"id"`
	CreateDto
}

type DeleteDto struct {
	Id   *int16  `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 {
	Id        int16       `json:"id"`
	Code      string      `json:"code"`
	Name      string      `json:"name"`
	Regencies []erb.Basic `json:"regencies,omitempty"`
}

func (d Province) ToResponse() ResponseDto {
	resp := ResponseDto{
		Id:        d.Id,
		Code:      d.Code,
		Name:      d.Name,
		Regencies: d.Regencies,
	}
	return resp
}

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