<?php

declare(strict_types=1);

use App\Models\Plan;

it('creates a plan with factory', function (): void {
    $plan = Plan::factory()->create();

    expect($plan)->toBeInstanceOf(Plan::class);
    expect($plan->status)->toBe('active');
});

it('casts features to array', function (): void {
    $plan = Plan::factory()->create([
        'features' => ['cpu' => '2 vCPU', 'ram' => '4GB'],
    ]);

    expect($plan->features)->toBeArray();
    expect($plan->features['cpu'])->toBe('2 vCPU');
});

it('checks availability correctly', function (): void {
    $plan = Plan::factory()->create(['status' => 'active', 'stock_quantity' => null]);
    expect($plan->isAvailable())->toBeTrue();

    $plan = Plan::factory()->create(['status' => 'hidden']);
    expect($plan->isAvailable())->toBeFalse();

    $plan = Plan::factory()->create(['status' => 'active', 'stock_quantity' => 0]);
    expect($plan->isAvailable())->toBeFalse();
});
