package core

import (
	"time"

	"github.com/golang-jwt/jwt/v5"
)

// TokenUserAgentCreatedViaCli is the user agent of token created via cli
const TokenUserAgentCreatedViaCli = ApplicationName + " Cli"

// TokenUserAgentForAPI is the user agent for API token
const TokenUserAgentForAPI = ApplicationName + " API"

// TokenUserAgentForMCP is the user agent for MCP token
const TokenUserAgentForMCP = ApplicationName + " MCP"

// TokenType represents token type
type TokenType byte

// Token types
const (
	USER_TOKEN_TYPE_NORMAL                         TokenType = 1
	USER_TOKEN_TYPE_REQUIRE_2FA                    TokenType = 2
	USER_TOKEN_TYPE_EMAIL_VERIFY                   TokenType = 3
	USER_TOKEN_TYPE_PASSWORD_RESET                 TokenType = 4
	USER_TOKEN_TYPE_MCP                            TokenType = 5
	USER_TOKEN_TYPE_OAUTH2_CALLBACK_REQUIRE_VERIFY TokenType = 6
	USER_TOKEN_TYPE_OAUTH2_CALLBACK                TokenType = 7
	USER_TOKEN_TYPE_API                            TokenType = 8
)

// UserTokenClaims represents user token
type UserTokenClaims struct {
	UserTokenId string    `json:"userTokenId"`
	Uid         int64     `json:"jti,string"`
	Username    string    `json:"username,omitempty"`
	Type        TokenType `json:"type"`
	IssuedAt    int64     `json:"iat"`
	ExpiresAt   int64     `json:"exp"`
}

// GetExpirationTime returns the expiration time of this token
func (c *UserTokenClaims) GetExpirationTime() (*jwt.NumericDate, error) {
	return &jwt.NumericDate{
		Time: time.Unix(c.ExpiresAt, 0),
	}, nil
}

// GetIssuedAt returns the issue time of this token
func (c *UserTokenClaims) GetIssuedAt() (*jwt.NumericDate, error) {
	return &jwt.NumericDate{
		Time: time.Unix(c.IssuedAt, 0),
	}, nil
}

// GetNotBefore returns the earliest valid time of this token
func (c *UserTokenClaims) GetNotBefore() (*jwt.NumericDate, error) {
	return &jwt.NumericDate{}, nil
}

// GetIssuer returns the issuer of this token
func (c *UserTokenClaims) GetIssuer() (string, error) {
	return "", nil
}

// GetSubject returns the subject of this token
func (c *UserTokenClaims) GetSubject() (string, error) {
	return "", nil
}

// GetAudience returns the audience of this token
func (c *UserTokenClaims) GetAudience() (jwt.ClaimStrings, error) {
	return jwt.ClaimStrings{}, nil
}
