package village

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	ed "simrs-vx/internal/domain/main-entities/district"
	epb "simrs-vx/internal/domain/main-entities/postal-region/base"
	evb "simrs-vx/internal/domain/main-entities/village/base"
)

type CreateDto struct {
	District_Code string  `json:"district_code" validate:"numeric;maxLength=6"`
	Code          *string `json:"code" validate:"numeric;maxLength=10"`
	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 {
	District_Code string `json:"district-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 {
	evb.Basic
	District      *ed.District `json:"district,omitempty"`
	PostalRegions []epb.Basic  `json:"postalRegions,omitempty"`
}

func (d Village) ToResponse() ResponseDto {
	resp := ResponseDto{
		Basic:         d.Basic,
		District:      d.District,
		PostalRegions: d.PostalRegions,
	}
	return resp
}

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