package ports

import (
	"context"
)

// EventType represents the type of account event
type EventType string

const (
	EventTypeAccountCreated   EventType = "account.created"
	EventTypeAccountUpdated   EventType = "account.updated"
	EventTypeAccountDeleted   EventType = "account.deleted"
	EventTypeAccountLogin     EventType = "account.login"
	EventTypeRecoveryStarted  EventType = "account.recovery.started"
	EventTypeRecoveryComplete EventType = "account.recovery.completed"
	EventTypeShareDeactivated EventType = "account.share.deactivated"
)

// AccountEvent represents an account-related event
type AccountEvent struct {
	Type      EventType
	AccountID string
	Data      map[string]interface{}
}

// EventPublisher defines the output port for publishing events
type EventPublisher interface {
	// Publish publishes an account event
	Publish(ctx context.Context, event AccountEvent) error

	// Close closes the publisher
	Close() error
}

// TokenService defines the output port for token operations
type TokenService interface {
	// GenerateAccessToken generates an access token for an account
	GenerateAccessToken(accountID, username string) (string, error)

	// GenerateRefreshToken generates a refresh token for an account
	GenerateRefreshToken(accountID string) (string, error)

	// ValidateAccessToken validates an access token
	ValidateAccessToken(token string) (claims map[string]interface{}, err error)

	// ValidateRefreshToken validates a refresh token
	ValidateRefreshToken(token string) (accountID string, err error)

	// RefreshAccessToken refreshes an access token using a refresh token
	RefreshAccessToken(refreshToken string) (accessToken string, err error)
}

// SessionCoordinatorClient defines the output port for session coordinator communication
type SessionCoordinatorClient interface {
	// GetSessionStatus gets the status of a keygen session
	GetSessionStatus(ctx context.Context, sessionID string) (status string, err error)

	// IsSessionCompleted checks if a session is completed
	IsSessionCompleted(ctx context.Context, sessionID string) (bool, error)
}

// CacheService defines the output port for caching
type CacheService interface {
	// Set sets a value in the cache
	Set(ctx context.Context, key string, value interface{}, ttlSeconds int) error

	// Get gets a value from the cache
	Get(ctx context.Context, key string) (interface{}, error)

	// Delete deletes a value from the cache
	Delete(ctx context.Context, key string) error

	// Exists checks if a key exists in the cache
	Exists(ctx context.Context, key string) (bool, error)
}
