<?php

declare(strict_types=1);

namespace App\Tests\Unit\Jobs;

use App\Domain\Jobs\JobOutcome;
use App\Domain\Jobs\JobStatus;
use PHPUnit\Framework\TestCase;

/**
 * The HTTP envelope is the public contract — every status in M05 maps to
 * a specific code (success=200, skipped_locked=409, failure=500). This
 * locks the mapping in.
 */
final class JobOutcomeTest extends TestCase
{
    public function testSuccessMapsTo200AndIncludesAllFields(): void
    {
        $outcome = new JobOutcome('demo', JobStatus::Success, 5, 12, 99);
        self::assertSame(200, $outcome->httpStatus());
        self::assertSame([
            'job' => 'demo',
            'status' => 'success',
            'items_processed' => 5,
            'duration_ms' => 12,
            'run_id' => 99,
        ], $outcome->toArray());
    }

    public function testSkippedLockedMapsTo409(): void
    {
        $outcome = new JobOutcome('demo', JobStatus::SkippedLocked, 0, 1, 100, 'lock held');
        self::assertSame(409, $outcome->httpStatus());
        $array = $outcome->toArray();
        self::assertSame('skipped_locked', $array['status']);
        self::assertSame('lock held', $array['error']);
    }

    public function testFailureMapsTo500(): void
    {
        $outcome = new JobOutcome('demo', JobStatus::Failure, 0, 200, 101, 'boom');
        self::assertSame(500, $outcome->httpStatus());
    }
}
