package oauth2

import "errors"

const (
	ErrorServerError          = "server_error"
	ErrorInvalidRequest       = "invalid_request"
	ErrorAccessDenied         = "access_denied"
	ErrorInvalidClient        = "invalid_client"
	ErrorInvalidGrant         = "invalid_grant"
	ErrorUnauthorizedClient   = "unauthorized_client"
	ErrorUnsupportedGrantType = "unsupported_grant_type"
	ErrorInvalidScope         = "invalid_scope"
)

var (
	ClientNotFoundError   = errors.New("Client not found.")
	URIMissingError       = errors.New("Redirect URI missing.")
	InvalidMethodError    = errors.New("Invalid request method.")
	InternalServerError   = errors.New("Internal server error.")
	ErrorNotAuthenticated = errors.New("Not authenticated.")
)

type URIFormatError string

func (err URIFormatError) Error() string {
	return "Invalid URI format: " + string(err)
}

type InvalidClientIDError string

func (err InvalidClientIDError) Error() string {
	return "Invalid client ID: " + string(err)
}

type URIMismatchError struct {
	uri      string
	mismatch string
}

func (err URIMismatchError) Error() string {
	return "Supplied redirect URI " + err.mismatch + " does not match the redirect in the database (" + err.uri + ")"
}

func NewURIMismatchError(uri, mismatch string) error {
	return URIMismatchError{
		uri:      uri,
		mismatch: mismatch,
	}
}
