<?php

namespace App\Models;

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

class PatientMedia extends Model
{
    protected $table = 'patient_media';

    protected $fillable = [
        'patient_id',
        'uploaded_by',
        'path',
        'original_name',
        'mime',
        'size',
        'title',
    ];

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

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

    public function isImage(): bool
    {
        return $this->mime !== null && str_starts_with($this->mime, 'image/');
    }

    public function isPdf(): bool
    {
        return $this->mime === 'application/pdf';
    }

    public function isVideo(): bool
    {
        return $this->mime !== null && str_starts_with($this->mime, 'video/');
    }
}
