<?php

namespace App\Console\Commands;

use App\Http\Controllers\PublicController;
use App\Jobs\ResizeImage;
use App\Models\Image;
use Illuminate\Console\Command;

class ImageCacheAll extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'imagecache:get-all';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Cache All Images in All Sizes on this Server (be carefull, take space)';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $images = Image::query()->get();
        foreach ($images as $image) {
            foreach (PublicController::$size as $size) {
                $this->info("Cache ".$image->id." as ".$size);
                ResizeImage::dispatchSync($image->id, $size);
            }
        }
    }
}
