<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

final class UploadBatchItem extends Model
{
    public const STATUS_UPLOADED = 'uploaded';
    public const STATUS_PROCESSING = 'processing';
    public const STATUS_NEEDS_METADATA = 'needs_metadata';
    public const STATUS_NEEDS_REVIEW = 'needs_review';
    public const STATUS_READY = 'ready';
    public const STATUS_FAILED = 'failed';
    public const STATUS_PUBLISHED = 'published';
    public const STATUS_DELETED = 'deleted';

    public const STAGE_QUEUED = 'queued';
    public const STAGE_STORED = 'stored';
    public const STAGE_THUMBNAILS = 'thumbnails';
    public const STAGE_VISION_ANALYSIS = 'vision_analysis';
    public const STAGE_MATURITY_CHECK = 'maturity_check';
    public const STAGE_METADATA_SUGGESTIONS = 'metadata_suggestions';
    public const STAGE_FINALIZED = 'finalized';

    protected $fillable = [
        'upload_batch_id',
        'user_id',
        'artwork_id',
        'original_filename',
        'status',
        'processing_stage',
        'error_code',
        'error_message',
        'metadata_completeness',
        'is_ready_to_publish',
        'uploaded_at',
        'processed_at',
        'published_at',
    ];

    protected $casts = [
        'is_ready_to_publish' => 'boolean',
        'uploaded_at' => 'datetime',
        'processed_at' => 'datetime',
        'published_at' => 'datetime',
    ];

    public function batch(): BelongsTo
    {
        return $this->belongsTo(UploadBatch::class, 'upload_batch_id');
    }

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

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