package services

import (
	"context"

	"github.com/RyanCopley/skybridge/faas/internal/domain"
	"github.com/RyanCopley/skybridge/faas/internal/runtime"
	"github.com/google/uuid"
)

// FunctionService provides business logic for function management
type FunctionService interface {
	Create(ctx context.Context, req *domain.CreateFunctionRequest, userID string) (*domain.FunctionDefinition, error)
	GetByID(ctx context.Context, id uuid.UUID) (*domain.FunctionDefinition, error)
	GetByName(ctx context.Context, appID, name string) (*domain.FunctionDefinition, error)
	Update(ctx context.Context, id uuid.UUID, req *domain.UpdateFunctionRequest, userID string) (*domain.FunctionDefinition, error)
	Delete(ctx context.Context, id uuid.UUID, userID string) error
	List(ctx context.Context, appID string, limit, offset int) ([]*domain.FunctionDefinition, error)
	GetByAppID(ctx context.Context, appID string) ([]*domain.FunctionDefinition, error)
	Deploy(ctx context.Context, id uuid.UUID, req *domain.DeployFunctionRequest, userID string) (*domain.DeployFunctionResponse, error)
}

// ExecutionService provides business logic for function execution
type ExecutionService interface {
	Execute(ctx context.Context, req *domain.ExecuteFunctionRequest, userID string) (*domain.ExecuteFunctionResponse, error)
	GetByID(ctx context.Context, id uuid.UUID) (*domain.FunctionExecution, error)
	List(ctx context.Context, functionID *uuid.UUID, limit, offset int) ([]*domain.FunctionExecution, error)
	GetByFunctionID(ctx context.Context, functionID uuid.UUID, limit, offset int) ([]*domain.FunctionExecution, error)
	Cancel(ctx context.Context, id uuid.UUID, userID string) error
	GetLogs(ctx context.Context, id uuid.UUID) ([]string, error)
	GetRunningExecutions(ctx context.Context) ([]*domain.FunctionExecution, error)
}

// RuntimeService provides runtime management capabilities
type RuntimeService interface {
	GetBackend(ctx context.Context, runtimeType string) (runtime.RuntimeBackend, error)
	ListSupportedRuntimes(ctx context.Context) ([]*domain.RuntimeInfo, error)
	HealthCheck(ctx context.Context, runtimeType string) error
	GetRuntimeInfo(ctx context.Context, runtimeType string) (*runtime.RuntimeInfo, error)
	ListContainers(ctx context.Context, runtimeType string) ([]runtime.ContainerInfo, error)
}

// AuthService provides authentication and authorization
type AuthService interface {
	GetAuthContext(ctx context.Context) (*domain.AuthContext, error)
	HasPermission(ctx context.Context, permission string) bool
	ValidatePermissions(ctx context.Context, permissions []string) error
}