<?php

namespace App\Domain\Workflow\Enums;

/** §19 task statuses. */
enum TaskStatus: string
{
    case Open = 'open';
    case InProgress = 'in_progress';
    case WaitingApplicant = 'waiting_applicant';
    case WaitingThirdParty = 'waiting_third_party';
    case Blocked = 'blocked';
    case Completed = 'completed';
    case Cancelled = 'cancelled';

    public function label(): string
    {
        return match ($this) {
            self::Open => 'Open',
            self::InProgress => 'In Progress',
            self::WaitingApplicant => 'Waiting on Applicant',
            self::WaitingThirdParty => 'Waiting on Third Party',
            self::Blocked => 'Blocked',
            self::Completed => 'Completed',
            self::Cancelled => 'Cancelled',
        };
    }

    /** Still someone's responsibility. */
    public function isOpen(): bool
    {
        return ! in_array($this, [self::Completed, self::Cancelled], true);
    }

    /** Waiting on someone else, so it should not read as overdue on us. */
    public function isWaiting(): bool
    {
        return in_array($this, [self::WaitingApplicant, self::WaitingThirdParty, self::Blocked], true);
    }

    public function requiresReason(): bool
    {
        return in_array($this, [self::Blocked, self::Cancelled], true);
    }

    /** @return array<int, string> */
    public static function values(): array
    {
        return array_column(self::cases(), 'value');
    }
}
