<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Media extends Model
{
    protected $fillable = [
        'name', 'file_name', 'mime_type', 'disk', 'path',
        'source_url', 'source_page', 'alt', 'file_size',
    ];

    public function getUrlAttribute(): string
    {
        return asset('storage/' . $this->path);
    }

    public function getThumbnailAttribute(): string
    {
        if (str_starts_with($this->mime_type ?? '', 'image/')) {
            return $this->url;
        }
        return asset('images/file-icon.png');
    }
}
