<?php
namespace Mehrab\Media\Models;

use Illuminate\Database\Eloquent\Model;
use Mehrab\Media\Services\MediaFileService;

class Media extends Model
{
    protected $casts = [
      'files' => 'json',
    ];

    public function thumb(){
        MediaFileService::thumb($this);
    }

    public function mid(){
        return '/storage/'.$this->files['500'] ?? null;
    }

    public function original(){
        return '/storage/'.$this->files['original'] ?? null;
    }

    public static function booted()
    {
        self::deleting(function ($media){
            MediaFileService::delete($media);
        });
    }
}
