<?php

namespace Aweos\Resizer\Classes;

use Aweos\Resizer\Lib\MediaPath;
use Log;
use Throwable;

class ResizeJob
{

    public function fire($job, $params)
    {
        try {
            list($file) = $params;
            app(ImageResizer::class)->generate(new MediaPath($file));
        } catch (Throwable $e) {
            Log::error('Resizing of image failed. Message: "'.$e->getMessage().'" in file "'.$e->getFile().'" on line '.$e->getLine());
            throw $e;
        }
    }

    public function failed($data, Throwable $e)
    {
        Log::error("Resizing of image failed", [
            'message' => $e->getMessage(),
            'exception' => $e,
            'data' => $data,
        ]);

        throw $e;
    }
}