<?php

namespace App\Domain\Shared\Domain\Model;

class FailedJob
{
    public function __construct(
        public readonly string $id,
        public readonly string $jobId,
        public readonly string $jobType,
        public readonly string $failureReason,
        public readonly array $context,
        public readonly \DateTimeImmutable $failedAt,
        public readonly int $attempt
    ) {
    }

    public static function fromJob(Job $job): self
    {
        return new self(
            id: uniqid('failed_', true),
            jobId: $job->id,
            jobType: $job->type,
            failureReason: $job->failureReason ?? 'Unknown error',
            context: $job->context,
            failedAt: new \DateTimeImmutable(),
            attempt: $job->attempts
        );
    }
}
