<?php

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

test('policies seeder creates the default managed environment with the configured slug identity', function () {
    config()->set('tenantpilot.supported_policy_types', []);

    $_ENV['INTUNE_TENANT_ID'] = 'test-tenant-id';
    $_SERVER['INTUNE_TENANT_ID'] = 'test-tenant-id';
    putenv('INTUNE_TENANT_ID=test-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('test-tenant-id');
    expect($tenant->external_id)->toBe('test-tenant-id');
});
