package postalregion

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	ev "simrs-vx/internal/domain/main-entities/village"
)

type CreateDto struct {
	Code         *string `json:"code" validate:"numeric;maxLength=5"`
	Village_Code string  `json:"village_code" validate:"numeric;maxLength=10"`
}

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

type FilterDto struct {
	Village_Code string `json:"village-code"`
	Code         string `json:"code"`
	Search       string `json:"search" gormhelper:"searchColumns=Code"`
}

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 {
	Id           uint32      `json:"id"`
	Village_Code string      `json:"village_code"`
	Village      *ev.Village `json:"village,omitempty"`
	Code         string      `json:"code"`
}

func (d PostalRegion) ToResponse() ResponseDto {
	resp := ResponseDto{
		Id:           d.Id,
		Village_Code: d.Village_Code,
		Village:      d.Village,
		Code:         d.Code,
	}
	return resp
}

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