<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;

/**
 * Очередь яруса 3 резерва канала миграции проектов.
 *
 * Spec: docs/superpowers/specs/2026-05-19-supplier-project-channel-failover-design.md §4.5
 *
 * @property int $id
 * @property int $project_id
 * @property string $platform
 * @property string $operation
 * @property string|null $external_id
 * @property array<string, mixed> $payload_snapshot
 * @property string $failure_reason
 * @property string $status
 * @property int|null $resolved_by_user_id
 * @property Carbon|null $created_at
 * @property Carbon|null $resolved_at
 *
 * @mixin IdeHelperSupplierManualSyncQueue
 */
class SupplierManualSyncQueue extends Model
{
    use HasFactory;

    protected $table = 'supplier_manual_sync_queue';

    public $timestamps = false;

    protected $fillable = [
        'project_id', 'platform', 'operation', 'external_id',
        'payload_snapshot', 'failure_reason', 'status',
        'resolved_by_user_id', 'created_at', 'resolved_at',
    ];

    protected $casts = [
        'payload_snapshot' => 'array',
        'created_at' => 'datetime',
        'resolved_at' => 'datetime',
    ];

    public function project(): BelongsTo
    {
        return $this->belongsTo(Project::class);
    }

    public function resolver(): BelongsTo
    {
        return $this->belongsTo(User::class, 'resolved_by_user_id');
    }
}
