package auth

import (
	"errors"
)

var (
	// The provided authentication method is not known to the server
	ErrUnknownAuthMethod = errors.New("unknown authentication method")
	// The user hasn't setup the provided authentication method
	ErrUnsupportedAuthMethod = errors.New("authentication method not supported for this user")
	// The given combination of token and account is invalid
	// Explicitly doesn't mention which part is valid to improve security
	ErrInvalidCombination = errors.New("invalid account and token combination")
	// The current authentication attempt has expired and needs to be restarted
	ErrProcessTimeout = errors.New("authentication process timed out")
	// A user may not login, for whatever reason
	ErrCantLogin = errors.New("user can't login")
	// Failed to decrypt the relevant data
	ErrDecryptionFailure = errors.New("failed to decrypt content")
	// The given totp token was recently (90 seconds) used for that username
	// For security reasons, this case will be caught and blocked
	ErrTotpRecentlyUsed = errors.New("totp token was used too recently")
	// The stored data for a passkey registration wasn't formatted correctly
	// and thus can't be used
	ErrInvalidPasskeyRegistrationData = errors.New(
		"stored passkey registration data was formatted badly",
	)
	// The given token has expired
	ErrTokenExpired = errors.New("token expired")
	// The given token doesn't exist
	ErrTokenNotFound = errors.New("token not found")
)

// Helper error type to combine two errors into one
// For when two different errors need to be passed together
// since fmt.Errorf doesn't really allow that as far as I know
type CombinedError struct {
	Err1, Err2 error
}

func (c *CombinedError) Is(e error) bool {
	return errors.Is(e, c.Err1) || errors.Is(e, c.Err2)
}

func (c *CombinedError) Error() string {
	return c.Err1.Error() + " + " + c.Err2.Error()
}

func (c *CombinedError) Unwrap() []error {
	return []error{c.Err1, c.Err2}
}
