package auth

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/auth"
	"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/auth/oauth/login/byPhone auth OauthLoginByPhone
//
// Oauth log in by phone code | Oauth 第三方登录，客户端获取换取手机号的code进行登录
//
// Oauth log in by phone code | Oauth 第三方登录，客户端获取换取手机号的code进行登录
//
// Parameters:
//  + name: body
//    require: true
//    in: body
//    type: OauthLoginByPhoneCodeReq
//
// Responses:
//  200: LoginResp

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

		l := auth.NewOauthLoginByPhoneLogic(r, r.Context(), svcCtx)
		resp, err := l.OauthLoginByPhone(&req)

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

	}
}
