<?php

use App\Models\Tenant;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;

uses(RefreshDatabase::class);

test('policies seeder creates default tenant with external_id', 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 = Tenant::query()->first();

    expect($tenant)->not->toBeNull();
    expect($tenant->tenant_id)->toBe('test-tenant-id');
    expect(Str::isUuid((string) $tenant->external_id))->toBeTrue();
});
