package district

import (
	"net/http"

	"git.noahlan.cn/noahlan/ntool-biz/zero/statusz"
	"github.com/zeromicro/go-zero/rest/httpx"

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

// swagger:route get /api/district/tree district GetDistrictTree
//
// get district tree | 获取地址树，整棵树
//
// get district tree | 获取地址树，整棵树
//
// Responses:
//  200: DistrictTree

func GetDistrictTreeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		const transErr = true
		var req types.DistrictReq
		if err := httpx.Parse(r, &req); err != nil {
			statusz.ResponseHandler(r, w, transErr, nil, err)
			return
		}

		l := district.NewGetDistrictTreeLogic(r, r.Context(), svcCtx)
		resp, err := l.GetDistrictTree(&req)

		statusz.ResponseHandler(r, w, transErr, resp, err)

	}
}
