<?php


namespace Mehrab\Media\Services;


use Illuminate\Support\Facades\Storage;
use Mehrab\Media\Models\Media;

abstract class DefaultFileService
{
    public static $media;

    public static function delete(Media $media)
    {
        foreach ($media->files as $file){
            if ($media->is_private){
                Storage::delete('private\\'.$file);
            }else{
                Storage::delete('public\\'.$file);
            }
        }
    }

//    abstract static function getFileName(){
//        return (static::$media->is_private ? 'app\\private\\' : 'app\\public\\') . self::$media->files['300'];
//    }

    public static function stream(Media $media){
        static::$media = $media;

        return readfile(storage_path(static::getFileName()));
//        return response()->file(storage_path(static::getFileName()));
//        $stream = Storage::readStream(storage_path(static::getFileName()));
//        return response()->stream(function () use ($stream){
//            fpassthru($stream);
//        },200,[
//            'Content-Type' => Storage::mimeType(static::getFileName()),
//            'Content-Disposition' => 'attachment; filename="' . static::$media->filename . '"',
//        ]);
    }
}
