<?php

declare(strict_types=1);

namespace App\Domain\Account\Enums;

/**
 * Hesap yaşam döngüsü durumları.
 *
 * Geçişler:
 *   pending  → active  (sysapi user-add başarılı)
 *   pending  → terminated (provisioning fail)
 *   active   → suspended  (manuel veya WHMCS webhook)
 *   suspended → active    (unsuspend)
 *   active/suspended → terminated  (silme — tar.gz yedek + Linux user kaldırma)
 */
enum AccountStatus: string
{
    case Pending = 'pending';
    case Active = 'active';
    case Suspended = 'suspended';
    case Terminated = 'terminated';

    public function label(): string
    {
        return match ($this) {
            self::Pending => 'Bekliyor',
            self::Active => 'Aktif',
            self::Suspended => 'Askıda',
            self::Terminated => 'Sonlandırıldı',
        };
    }

    public function color(): string
    {
        return match ($this) {
            self::Pending => 'amber',
            self::Active => 'green',
            self::Suspended => 'orange',
            self::Terminated => 'red',
        };
    }

    public function canTransitionTo(self $next): bool
    {
        return match ([$this, $next]) {
            [self::Pending, self::Active] => true,
            [self::Pending, self::Terminated] => true,
            [self::Active, self::Suspended] => true,
            [self::Active, self::Terminated] => true,
            [self::Suspended, self::Active] => true,
            [self::Suspended, self::Terminated] => true,
            default => false,
        };
    }
}
