package district

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	edb "simrs-vx/internal/domain/main-entities/district/base"
	er "simrs-vx/internal/domain/main-entities/regency"
	evb "simrs-vx/internal/domain/main-entities/village/base"
)

type CreateDto struct {
	Regency_Code string  `json:"regency_code" validate:"numeric;maxLength=4"`
	Code         *string `json:"code" validate:"numeric;maxLength=6"`
	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 {
	Regency_Code string `json:"regency-code"`
	Code         string `json:"code"`
	Name         string `json:"name"`
	Search       string `json:"search" gormhelper:"searchColumns=Code,Name"`
}

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

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

type DeleteDto struct {
	Id   *uint32 `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 {
	edb.Basic
	Regency  *er.Regency  `json:"regency,omitempty"`
	Villages []*evb.Basic `json:"villages,omitempty"`
}

func (d District) ToResponse() ResponseDto {
	resp := ResponseDto(d)
	return resp
}

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