<?php

namespace App\Domain\Payments\Enums;

/**
 * Payment lifecycle (§29A, §70).
 *
 * A payment only counts against a balance once it is confirmed. Cash is
 * confirmed on receipt; a bank deposit waits until someone has checked the slip.
 */
enum PaymentStatus: string
{
    case Pending = 'pending';
    case Confirmed = 'confirmed';
    case Rejected = 'rejected';
    case Reversed = 'reversed';

    public function label(): string
    {
        return match ($this) {
            self::Pending => 'Awaiting Verification',
            self::Confirmed => 'Confirmed',
            self::Rejected => 'Rejected',
            self::Reversed => 'Reversed',
        };
    }

    /** Whether this payment reduces what the applicant owes. */
    public function countsAsPaid(): bool
    {
        return $this === self::Confirmed;
    }

    public function isFinal(): bool
    {
        return in_array($this, [self::Rejected, self::Reversed], true);
    }

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