<?php

namespace App\Enums;

enum InvoiceSyncStatus: string
{
    case Draft = 'draft';
    case Queued = 'queued';
    case Syncing = 'syncing';
    case Synced = 'synced';
    case Failed = 'failed';

    public function label(): string
    {
        return match ($this) {
            self::Draft => 'Draft',
            self::Queued => 'Queued for Sync',
            self::Syncing => 'Syncing...',
            self::Synced => 'Synced with FBR',
            self::Failed => 'Sync Failed',
        };
    }

    public function isFinal(): bool
    {
        return $this === self::Synced;
    }

    public function canEdit(): bool
    {
        // Once synced, the invoice is locked — corrections must go through
        // Debit/Credit Note, not a direct edit.
        return in_array($this, [self::Draft, self::Failed], true);
    }

    public function canQueue(): bool
    {
        return in_array($this, [self::Draft, self::Failed], true);
    }
}
