<?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\EmbedVideo;

class CreateVideoSizes implements ShouldQueue, ShouldBeUnique
{
    use Dispatchable;
    use InteractsWithQueue;
    use Queueable;
    use SerializesModels;

    public $embed_video;
    public $size;

    public $timeout = 1800;
    public $uniqueFor = 3600;
    public $tries = 1;

    /**
     * The unique ID of the job.
     */
    public function uniqueId(): string
    {
        return $this->embed_video->id.'-'.$this->size;
    }

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(EmbedVideo $embed_video, $size)
    {
        $this->embed_video = $embed_video;
        $this->size = $size;
        $this->onQueue('video');
        $this->onConnection('video');
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $this->embed_video->createSizes($this->size);
    }
}
