package district

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

	"git.noahlan.cn/n-admin/n-admin-server/api/internal/svc"
	"git.noahlan.cn/n-admin/n-admin-server/api/internal/types"

	"net/http"
)

type GetDistrictNameLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	r      *http.Request
}

func NewGetDistrictNameLogic(r *http.Request, ctx context.Context, svcCtx *svc.ServiceContext) *GetDistrictNameLogic {
	return &GetDistrictNameLogic{
		r:      r,
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetDistrictNameLogic) GetDistrictName(req *types.GetDistrictNameReq) (resp *types.GetDistrictNameResp, err error) {
	rpcResp, err := l.svcCtx.CoreRpc.GetDistrictName(l.ctx, &core.GetDistrictNameReq{
		Code:      req.Code,
		Separator: req.Separator,
	})
	if err != nil {
		return nil, err
	}
	resp = &types.GetDistrictNameResp{
		Code:     rpcResp.Code,
		Name:     rpcResp.Name,
		NameList: rpcResp.NameList,
	}
	return
}
