<?php

namespace App\Enums;

enum PaymentStatus: string
{
    case Pending = 'pending';
    case Processing = 'processing';
    case Paid = 'paid';
    case Failed = 'failed';
    case Cancelled = 'cancelled';
    case Refunded = 'refunded';

    public function label(): string
    {
        return ucfirst($this->value);
    }

    public function color(): string
    {
        return match ($this) {
            self::Pending => 'slate',
            self::Processing => 'sky',
            self::Paid => 'emerald',
            self::Failed => 'red',
            self::Cancelled => 'slate',
            self::Refunded => 'amber',
        };
    }

    public function isSettled(): bool
    {
        return $this === self::Paid;
    }

    /** A payment in these states may still be transitioned by a provider callback. */
    public function isOpen(): bool
    {
        return in_array($this, [self::Pending, self::Processing], true);
    }
}
