//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2025-03-04 16:08:06
// Distributed under terms of the MIT license.
//

package auth

import (
	"github.com/veypi/vigo"
)

var Router = vigo.NewRouter()

func init() {
	// === 公开路由（跳过父级认证中间件）===
	// 登录/注册等接口不需要认证
	Router.Post("/login", "用户登录", vigo.SkipBefore, login)
	Router.Post("/login/code", "验证码登录", vigo.SkipBefore, loginWithCode)
	Router.Post("/register", "用户注册", vigo.SkipBefore, register)
	Router.Post("/refresh", "刷新Token", vigo.SkipBefore, refresh)
	Router.Post("/logout", "用户登出", logout)

	// 登录方式/提供商（公开端点）
	Router.Get("/login-methods", "支持的登录方式", vigo.SkipBefore, loginMethods)
	Router.Get("/authorize/thirdparty", "第三方登录授权", vigo.SkipBefore, authorizeThirdParty)
	Router.Get("/callback/{provider}", "第三方登录回调", vigo.SkipBefore, callbackThirdParty)
	Router.Post("/bind", "绑定第三方账号", vigo.SkipBefore, bindThirdParty)
	Router.Post("/bind-register", "绑定并注册", vigo.SkipBefore, bindWithRegister)

	// === 认证用户接口（需要登录）===
	// 用户搜索（返回公开信息）
	Router.Get("/users", "搜索用户", searchUsers)
	Router.Post("/users", "批量查询用户", searchUsers)

	// 当前用户（需要认证）
	meRouter := Router.SubRouter("/me")
	meRouter.Get("/", "获取当前用户信息", me)
	meRouter.Patch("/", "更新当前用户信息", updateMe)
	meRouter.Post("/change-password", "修改密码", changePassword)
	// 第三方账号绑定
	meRouter.Get("/bindings", "第三方账号绑定列表", listBindings)
	meRouter.Post("/bindings", "绑定第三方账号", authorizeThirdParty)
	meRouter.Delete("/bindings/{provider}", "解绑第三方账号", unbindThirdParty)
}
