package handler

import (
	"net/http"
	"reflect"

	"fusenapi/utils/basic"

	"fusenapi/server/home-user-auth/internal/logic"
	"fusenapi/server/home-user-auth/internal/svc"
	"fusenapi/server/home-user-auth/internal/types"
)

func UserAddAddressHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {

		var req types.RequestAddAddress
		userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
		if err != nil {
			return
		}

		// 创建一个业务逻辑层实例
		l := logic.NewUserAddAddressLogic(r.Context(), svcCtx)

		rl := reflect.ValueOf(l)
		basic.BeforeLogic(w, r, rl)

		resp := l.UserAddAddress(&req, userinfo)

		if !basic.AfterLogic(w, r, rl, resp) {
			basic.NormalAfterLogic(w, r, resp)
		}
	}
}