package svc

import (
	"context"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
)

var DistrictHelperInst = NewDistrictHelper()

type (
	DistrictHelper struct {
		getNameFn GetDistrictNameFunc
		svcCtx    *ServiceContext
	}

	DistrictCacheItem struct {
		Code     string   // 区域代码
		NameList []string // 区域名称列表(从根节点开始)
	}

	GetDistrictNameFunc func(ctx context.Context, svcCtx *ServiceContext, code, separator string) (*core.GetDistrictNameResp, error)
)

func NewDistrictHelper() *DistrictHelper {
	return &DistrictHelper{}
}

func (h *DistrictHelper) SetGetDistrictNameFn(fn GetDistrictNameFunc) {
	h.getNameFn = fn
}

func (h *DistrictHelper) GetDistrictName(ctx context.Context, code, separator string) (*core.GetDistrictNameResp, error) {
	return h.getNameFn(ctx, h.svcCtx, code, separator)
}
