<?php

declare(strict_types=1);

use App\Models\Project;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Tests\Concerns\SharesSupplierPdo;

uses(DatabaseTransactions::class);
uses(SharesSupplierPdo::class);

beforeEach(function () {
    DB::statement("SELECT set_config('app.current_tenant_id', '0', true)");
});

// H (балансовый блок): ProjectResource отдаёт признак блокировки на фронт,
// чтобы карточка показала «Приостановлен — не хватает баланса».

it('exposes balance_blocked=true for a blocked project', function () {
    $tenant = Tenant::factory()->create();
    $user = User::factory()->create(['tenant_id' => $tenant->id]);
    $project = Project::factory()->for($tenant)->create(['preflight_blocked_at' => now()]);

    $this->actingAs($user)->getJson("/api/projects/{$project->id}")
        ->assertOk()
        ->assertJsonPath('data.balance_blocked', true);
});

it('exposes balance_blocked=false for a normal project', function () {
    $tenant = Tenant::factory()->create();
    $user = User::factory()->create(['tenant_id' => $tenant->id]);
    $project = Project::factory()->for($tenant)->create(['preflight_blocked_at' => null]);

    $this->actingAs($user)->getJson("/api/projects/{$project->id}")
        ->assertOk()
        ->assertJsonPath('data.balance_blocked', false);
});
