package captcha

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/captcha"
	"git.noahlan.cn/n-admin/n-admin-server/api/internal/svc"
	"git.noahlan.cn/n-admin/n-admin-server/api/internal/types"
)

// swagger:route post /api/captcha/validate captcha ValidateCaptcha
//
// Validating captcha | 验证验证码正确性
//
// Validating captcha | 验证验证码正确性
//
// Parameters:
//  + name: body
//    require: true
//    in: body
//    type: ValidateCaptchaReq
//

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

		l := captcha.NewValidateCaptchaLogic(r, r.Context(), svcCtx)
		err := l.ValidateCaptcha(&req)

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

	}
}
