<?php

namespace App\Models\Witness;

use App\Models\Document\Document;
use App\Models\Dsar\DsarEvidenceItem;
use App\Models\User\User;
use App\Trait\BelongsToSolicitor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * A document page promoted as an exhibit to a witness statement. Usually
 * promoted from a confirmed DsarEvidenceItem, but a document page can be
 * exhibited directly too.
 */
class WitnessStatementExhibit extends Model
{
    use BelongsToSolicitor;

    protected $fillable = [
        'solicitor_id',
        'witness_statement_id',
        'dsar_evidence_item_id',
        'document_id',
        'page',
        'exhibit_ref',
        'label',
        'added_by',
    ];

    protected $casts = [
        'page' => 'integer',
    ];

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

    public function evidenceItem(): BelongsTo
    {
        return $this->belongsTo(DsarEvidenceItem::class, 'dsar_evidence_item_id');
    }

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

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