package auth

import (
	"github.com/gin-gonic/gin"

	"github.com/tidbcloud/tidb-management-service/tidb-mgmt-portal/domain/adapter/account"
	"github.com/tidbcloud/tidb-management-service/tidb-mgmt-portal/pkg/config"
)

type Service interface {
	// Auth is a middleware to authenticate the request.
	// otherwise, it should abort the request with the unauthorized status code.
	TransformAuthnCtx(ctx *gin.Context)
	CheckUserAndPermission() gin.HandlerFunc
	RemoveApiKeyHeader() gin.HandlerFunc
}

func NewAuthService(acc account.Client) Service {
	if config.Global().Auth.LocalMode {
		return newFakeAuthService()
	}
	return newAuthAuthService(acc)
}
