<?php

namespace App\Domain\Commissions\Enums;

/** Commission lifecycle (§13A). */
enum CommissionStatus: string
{
    case Accrued = 'accrued';
    case UnderReview = 'under_review';
    case Approved = 'approved';
    case Payable = 'payable';
    case PartiallyPaid = 'partially_paid';
    case Paid = 'paid';
    case Reversed = 'reversed';
    case Cancelled = 'cancelled';

    public function label(): string
    {
        return match ($this) {
            self::Accrued => 'Accrued',
            self::UnderReview => 'Under Review',
            self::Approved => 'Approved',
            self::Payable => 'Payable',
            self::PartiallyPaid => 'Partially Paid',
            self::Paid => 'Paid',
            self::Reversed => 'Reversed',
            self::Cancelled => 'Cancelled',
        };
    }

    /** Whether this amount is owed to the agent right now. */
    public function isOutstanding(): bool
    {
        return in_array($this, [self::Approved, self::Payable, self::PartiallyPaid], true);
    }

    /** Whether the amount can still be clawed back. */
    public function isReversible(): bool
    {
        return ! in_array($this, [self::Reversed, self::Cancelled], true);
    }

    public function canJoinSettlement(): bool
    {
        return in_array($this, [self::Approved, self::Payable], true);
    }

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