<?php

namespace Tests\Unit\Sale;

use App\Domains\Logging\Models\ValueChange;
use App\Domains\Sale\Resources\AdminApp\SaleModificationResource;
use Carbon\CarbonImmutable;
use Illuminate\Http\Request;
use Tests\TestCase;

class SaleModificationResourceTest extends TestCase
{
    public function test_it_serializes_the_change_instant_as_utc_iso_8601(): void
    {
        $modification = (new ValueChange)->forceFill([
            'id' => 1,
            'trackable_id' => 33,
            'attribute' => 'status',
            'old_value' => 'pending_payment',
            'new_value' => 'cancelled',
            'changed_at' => CarbonImmutable::parse('2026-08-24 17:53:00', 'UTC'),
            'actor_type' => 'system',
        ]);
        $modification->setRelation('trackable', null);
        $modification->setRelation('user', null);

        $data = (new SaleModificationResource($modification))->resolve(Request::create('/'));

        $this->assertSame('2026-08-24T17:53:00+00:00', $data['changed_at']);
        $this->assertSame('2026-08-24', $data['date']);
        $this->assertSame('17:53:00', $data['time']);
    }
}
