<?php

namespace App\Models\Print;

use App\Models\Document\Document;
use App\Models\User\User;
use App\Trait\BelongsToSolicitor;
use Illuminate\Database\Eloquent\Model;

class PrintQueueItem extends Model {
    protected $table = 'print_queue';

    protected $fillable = [
        'solicitor_id',
        'document_id',
        'file_path',
        'owner_type',
        'owner_id',
        'user_id',
    ];

    use BelongsToSolicitor;

    public function document() {
        return $this->belongsTo(Document::class);
    }

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

    /**
     * The direct owner — only set for path-based queue entries.
     * For document-based entries the owner lives on the Document itself.
     */
    public function owner() {
        return $this->morphTo();
    }

    public function isPathBased(): bool {
        return $this->file_path !== null;
    }
}
