<?php

declare(strict_types=1);

namespace App\Framework\Console\Health;

final readonly class HealthCheckResult
{
    public function __construct(
        public HealthStatus $status,
        public string $message,
        public array $details = [],
        public ?string $recommendation = null
    ) {
    }

    public static function healthy(string $message = 'OK', array $details = []): self
    {
        return new self(HealthStatus::HEALTHY, $message, $details);
    }

    public static function warning(string $message, array $details = [], ?string $recommendation = null): self
    {
        return new self(HealthStatus::WARNING, $message, $details, $recommendation);
    }

    public static function unhealthy(string $message, array $details = [], ?string $recommendation = null): self
    {
        return new self(HealthStatus::UNHEALTHY, $message, $details, $recommendation);
    }

    public function isHealthy(): bool
    {
        return $this->status === HealthStatus::HEALTHY;
    }

    public function isWarning(): bool
    {
        return $this->status === HealthStatus::WARNING;
    }

    public function isUnhealthy(): bool
    {
        return $this->status === HealthStatus::UNHEALTHY;
    }

    public function toArray(): array
    {
        return [
            'status' => $this->status->value,
            'message' => $this->message,
            'details' => $this->details,
            'recommendation' => $this->recommendation,
        ];
    }
}
