<?php

declare(strict_types=1);

namespace App\Framework\Process\ValueObjects\Health;

/**
 * Einzelner Health Check.
 */
final readonly class HealthCheck
{
    public function __construct(
        public string $name,
        public HealthStatus $status,
        public string $message,
        public float $value,
        public float $threshold,
        public string $unit = ''
    ) {
    }

    /**
     * Erstellt einen erfolgreichen Health Check.
     */
    public static function healthy(
        string $name,
        string $message,
        float $value = 0.0,
        float $threshold = 0.0,
        string $unit = ''
    ): self {
        return new self($name, HealthStatus::HEALTHY, $message, $value, $threshold, $unit);
    }

    /**
     * Erstellt einen degraded Health Check.
     */
    public static function degraded(
        string $name,
        string $message,
        float $value = 0.0,
        float $threshold = 0.0,
        string $unit = ''
    ): self {
        return new self($name, HealthStatus::DEGRADED, $message, $value, $threshold, $unit);
    }

    /**
     * Erstellt einen unhealthy Health Check.
     */
    public static function unhealthy(
        string $name,
        string $message,
        float $value = 0.0,
        float $threshold = 0.0,
        string $unit = ''
    ): self {
        return new self($name, HealthStatus::UNHEALTHY, $message, $value, $threshold, $unit);
    }

    /**
     * Konvertiert zu Array.
     *
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'name' => $this->name,
            'status' => $this->status->value,
            'message' => $this->message,
            'value' => $this->value,
            'threshold' => $this->threshold,
            'unit' => $this->unit,
        ];
    }
}
