package errors

import (
	"net/http"

	"github.com/tidbcloud/pkgv2/bizerr"
	"github.com/tidbcloud/tiinf/errs"
)

const (
	// TODO: move it to pkgv2/svcid
	Central = 2
)

var (
	ErrCodeEmailAddressInUse           = int64(bizerr.NewBusinessErrCode(Central, 1, "ErrCodeEmailAddressInUse"))
	ErrCodeUserPasswordPolicy          = int64(bizerr.NewBusinessErrCode(Central, 2, "ErrCodeUserPasswordPolicy"))
	ErrCodeDuplicatedThirdPartyAccount = int64(bizerr.NewBusinessErrCode(Central, 3, "ErrCodeDuplicatedThirdPartyAccount"))
	ErrCodeClusterNotSupportDbUser     = int64(bizerr.NewBusinessErrCode(Central, 4, "ErrCodeClusterNotSupportDbUser"))
	ErrCodeEmailAddressNotVerify       = int64(bizerr.NewBusinessErrCode(Central, 5, "ErrCodeEmailAddressNotVerify"))
	ErrCodeMessageForFrontEnd          = int64(bizerr.NewBusinessErrCode(Central, 6, ""))
	//ErrCodeTokenInvalid                = int64(bizerr.NewBusinessErrCode(Central, 7, "ErrCodeTokenInvalid"))
	ErrCodeUserNotInOrg = int64(bizerr.NewBusinessErrCode(Central, 7, "ErrCodeUserNotInOrg"))
)

var (
	ErrEmailAddressInUse           = errs.RegisterErrorType(errs.ErrBadRequest, http.StatusBadRequest, ErrCodeEmailAddressInUse)
	ErrUserPasswordPolicy          = errs.RegisterErrorType(errs.ErrBadRequest, http.StatusBadRequest, ErrCodeUserPasswordPolicy)
	ErrDuplicatedThirdPartyAccount = errs.RegisterErrorType(errs.ErrBadRequest, http.StatusBadRequest, ErrCodeDuplicatedThirdPartyAccount)
	ErrClusterNotSupportDbUser     = errs.RegisterErrorType(errs.ErrBadRequest, http.StatusUnprocessableEntity, ErrCodeClusterNotSupportDbUser)
	ErrEmailAddressNotVerify       = errs.RegisterErrorType(errs.ErrBadRequest, http.StatusBadRequest, ErrCodeEmailAddressNotVerify)
	ErrMessageForFrontEnd          = errs.RegisterErrorType(errs.ErrBadRequest, http.StatusBadRequest, ErrCodeMessageForFrontEnd)
	//ErrTokenInvalid                = errs.RegisterErrorType(errs.ErrBadRequest, http.StatusBadRequest, ErrCodeEmailAddressNotVerify)
	ErrUserNotInOrg = errs.RegisterErrorType(errs.ErrBadRequest, http.StatusBadRequest, ErrCodeUserNotInOrg)
)

func NewEmailAddressInUseError(msg string, cause error) errs.Error {
	return errs.NewError(ErrEmailAddressInUse, msg, cause)
}

func NewEmailAddressNotVerifyError(msg string, cause error) errs.Error {
	return errs.NewError(ErrEmailAddressNotVerify, msg, cause)
}

func NewUserPasswordPolicyError(msg string, cause error) errs.Error {
	return errs.NewError(ErrUserPasswordPolicy, msg, cause)
}

func NewErrDuplicatedThirdPartyAccountError(msg string, cause error) errs.Error {
	return errs.NewError(ErrDuplicatedThirdPartyAccount, msg, cause)
}

func NewErrClusterNotSupportDbUserError(msg string, cause error) errs.Error {
	return errs.NewError(ErrClusterNotSupportDbUser, msg, cause)
}
func NewErrMessageForFrontEnd(msg string, cause error) errs.Error {
	return errs.NewError(ErrMessageForFrontEnd, msg, cause)
}

func NewErrUserNotInOrg(msg string, cause error) errs.Error {
	return errs.NewError(ErrUserNotInOrg, msg, cause)
}
