<?php

declare(strict_types=1);

namespace App\Framework\ErrorBoundaries\CircuitBreaker;

/**
 * Circuit breaker states for error boundaries
 */
enum BoundaryCircuitState: string
{
    case CLOSED = 'closed';
    case OPEN = 'open';
    case HALF_OPEN = 'half_open';

    /**
     * Get human-readable description
     */
    public function getDescription(): string
    {
        return match ($this) {
            self::CLOSED => 'Circuit is closed - operations are allowed',
            self::OPEN => 'Circuit is open - operations are blocked',
            self::HALF_OPEN => 'Circuit is half-open - limited operations are allowed for testing',
        };
    }

    /**
     * Check if operations are allowed in this state
     */
    public function allowsOperations(): bool
    {
        return match ($this) {
            self::CLOSED => true,
            self::OPEN => false,
            self::HALF_OPEN => true, // Limited operations allowed
        };
    }

    /**
     * Get the severity level of this state
     */
    public function getSeverity(): string
    {
        return match ($this) {
            self::CLOSED => 'info',
            self::OPEN => 'error',
            self::HALF_OPEN => 'warning',
        };
    }
}
