<?php

declare(strict_types=1);

use App\Http\Resources\ProjectResource;
use App\Models\Project;
use App\Models\Tenant;
use Carbon\CarbonImmutable;
use Illuminate\Foundation\Testing\DatabaseTransactions;

uses(DatabaseTransactions::class);

it('ProjectResource includes applies_from as ISO8601 when set', function (): void {
    $tenant = Tenant::factory()->create();
    $project = Project::factory()->for($tenant)->create();
    $project->applies_from = CarbonImmutable::parse('2026-05-29 21:00:00', 'Europe/Moscow');

    $resource = (new ProjectResource($project))->toArray(request());

    expect($resource)->toHaveKey('applies_from');
    expect($resource['applies_from'])->toBe('2026-05-29T21:00:00+03:00');
});

it('ProjectResource applies_from is null when not set', function (): void {
    $tenant = Tenant::factory()->create();
    $project = Project::factory()->for($tenant)->create();
    // applies_from не установлен

    $resource = (new ProjectResource($project))->toArray(request());

    expect($resource)->toHaveKey('applies_from');
    expect($resource['applies_from'])->toBeNull();
});
