<?php

use App\Models\Finding;

it('deletes legacy drift findings and keeps baseline compare drift findings', function (): void {
    $legacyNullSource = Finding::factory()->create([
        'finding_type' => Finding::FINDING_TYPE_DRIFT,
        'source' => null,
    ]);

    $legacyOtherSource = Finding::factory()->create([
        'finding_type' => Finding::FINDING_TYPE_DRIFT,
        'source' => 'legacy.drift',
    ]);

    $baselineCompareFinding = Finding::factory()->create([
        'finding_type' => Finding::FINDING_TYPE_DRIFT,
        'source' => 'baseline.compare',
    ]);

    $nonDriftFinding = Finding::factory()->permissionPosture()->create();

    $migrationPath = base_path('database/migrations/2026_03_05_000001_delete_legacy_drift_findings.php');

    expect(file_exists($migrationPath))->toBeTrue();

    $migration = require $migrationPath;

    $migration->up();

    expect(Finding::query()->whereKey($legacyNullSource->getKey())->exists())->toBeFalse();
    expect(Finding::query()->whereKey($legacyOtherSource->getKey())->exists())->toBeFalse();
    expect(Finding::query()->whereKey($baselineCompareFinding->getKey())->exists())->toBeTrue();
    expect(Finding::query()->whereKey($nonDriftFinding->getKey())->exists())->toBeTrue();
});
