<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

use App\Models\Photo;
use Illuminate\Support\Arr;

class CreatePhotoImage implements ShouldQueue
{
    use Dispatchable;
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;

    public $photo;
    public $size;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(Photo $photo, $size)
    {
        $this->photo = $photo;
        $this->size = $size;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $widths = [
            'small' => 576,
            'medium' => 768,
            'large' => 1152,
            'retina' => 2304,
        ];
        $this->photo->createImage(Arr::get($widths, $this->size), $this->size);
    }
}
