<?php

use App\Services\Operations\BulkIdempotencyFingerprint;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

it('builds a deterministic 64 char sha256 fingerprint for bulk operations', function () {
    /** @var BulkIdempotencyFingerprint $fingerprints */
    $fingerprints = app(BulkIdempotencyFingerprint::class);

    $selectionA = ['kind' => 'ids', 'ids_hash' => hash('sha256', 'a,b,c')];
    $selectionB = ['kind' => 'ids', 'ids_hash' => hash('sha256', 'a,b,d')];

    $keyA1 = $fingerprints->build('policy.delete', ['entra_tenant_id' => 'tenant-a'], $selectionA);
    $keyA2 = $fingerprints->build('policy.delete', ['entra_tenant_id' => 'tenant-a'], $selectionA);
    $keyB = $fingerprints->build('policy.delete', ['entra_tenant_id' => 'tenant-a'], $selectionB);

    expect($keyA1)->toBe($keyA2)
        ->and($keyA1)->not->toBe($keyB)
        ->and($keyA1)->toMatch('/^[a-f0-9]{64}$/');
});
