<?php

namespace App\Models\Document;

use App\Casts\FileSize;
use App\Models\Dsar\DsarEvidenceItem;
use App\Models\Institution\Institution;
use App\Models\User\User;
use App\Trait\BelongsToSolicitor;
use App\Trait\HasEvidenceProductivity;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Document extends Model {
    protected $table = 'documents';
    protected $fillable = [
        'solicitor_id',
        'user_id',
        'display_name',
        'file_name',
        'file_type',
        'file_size',
        'type_id',
        'institution_id',
        'institution_is_suggested',
        'evidence_status',
        'evidence_excluded',
    ];

    protected $casts = [
        'file_size'                => FileSize::class,
        'institution_is_suggested' => 'boolean',
        'evidence_excluded'        => 'boolean',
    ];

    use BelongsToSolicitor, HasEvidenceProductivity;

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

    public function type() {
        return $this->belongsTo(DocumentType::class);
    }

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

    public function owner() {
        return $this->morphTo();
    }

    public function evidenceItems(): HasMany
    {
        return $this->hasMany(DsarEvidenceItem::class);
    }
}
