<?php
/**
 * BookiFlex Background Jobs Extension
 *
 * @package    BookiFlex
 * @subpackage BackgroundJobs
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */

declare(strict_types=1);

namespace BookiFlex\Extensions\BackgroundJobs\Contract;

defined( 'ABSPATH' ) || exit;

/**
 * Health Status Value Object
 *
 * Represents the current health status of the ActionScheduler queue.
 */
class HealthStatus
{
    public const STATUS_OK = 'ok';
    public const STATUS_WARNING = 'warning';
    public const STATUS_DELAYED = 'delayed';
    public const STATUS_UNKNOWN = 'unknown';

    public function __construct(
        public readonly string $status,
        public readonly ?int $lastRunTime,
        public readonly int $pendingJobsCount,
        public readonly ?int $timeSinceLastRun
    ) {
    }

    public function isDelayed(): bool
    {
        return $this->status === self::STATUS_DELAYED;
    }

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

    public function isOk(): bool
    {
        return $this->status === self::STATUS_OK;
    }

    public function isUnknown(): bool
    {
        return $this->status === self::STATUS_UNKNOWN;
    }

    public function toArray(): array
    {
        return [
            'status' => $this->status,
            'last_run_time' => $this->lastRunTime,
            'pending_jobs_count' => $this->pendingJobsCount,
            'time_since_last_run' => $this->timeSinceLastRun,
        ];
    }
}
