<?php

use App\Models\Instance;
use App\Models\Order;
use App\Models\ProvisioningRun;
use Tests\Support\Steps\ProbeCustomerStep;

it('resolves order, instance and plan from the run', function () {
    $order = Order::factory()->withSubscription()->create(['plan' => 'team']);
    $instance = Instance::factory()->create();
    $run = ProvisioningRun::factory()->create([
        'subject_type' => Order::class,
        'subject_id' => $order->id,
        'pipeline' => 'customer',
        'context' => ['instance_id' => $instance->id],
    ]);

    $step = new ProbeCustomerStep;

    expect($step->orderOf($run)->is($order))->toBeTrue()
        ->and($step->instanceOf($run)->is($instance))->toBeTrue()
        ->and($step->planOf($run)['quota_gb'])->toBe(500)
        ->and($step->label())->toBe('provisioning.step.probe');
});

it('registers the 15-step customer pipeline in config', function () {
    expect(config('provisioning.pipelines.customer'))->toHaveCount(15);
});

it('takes the blueprint from the catalogue, which no longer lives in config', function () {
    expect(config('provisioning.plans'))->toBeNull()
        ->and(app(App\Services\Billing\PlanCatalogue::class)->currentVersion('start')->template_vmid)->toBe(9000);
});
