<?php

use App\Models\ManagedEnvironment;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);

test('policies seeder keeps the seeded managed environment identity on the slug alias', function (): void {
    config()->set('tenantpilot.supported_policy_types', []);

    $_ENV['INTUNE_TENANT_ID'] = 'seed-tenant-id';
    $_SERVER['INTUNE_TENANT_ID'] = 'seed-tenant-id';
    putenv('INTUNE_TENANT_ID=seed-tenant-id');

    $this->artisan('db:seed', ['--class' => Database\Seeders\PoliciesSeeder::class])
        ->assertExitCode(0);

    $tenant = ManagedEnvironment::query()->first();

    expect($tenant)->not->toBeNull();
    expect($tenant?->managed_environment_id)->toBe('seed-tenant-id');
    expect($tenant?->external_id)->toBe('seed-tenant-id');
});
