<?php

namespace App\Importers;

use App\ImportsMedia;
use Illuminate\Http\UploadedFile;
use App\Importers\Image\Jobs\{ImportImage, GenerateFullscreen, GenerateThumbnail};
use App\Models\Image as ImageModel;
use App\Models\Album;

class Image implements ImportsMedia {
    
    public static function supports(UploadedFile $file): bool {
        $supportedMimes = config('gallery.image.suffixes', ['png', 'gif', 'bmp', 'svg', 'avi', 'jpg', 'jpeg']);
        return in_array($file->guessExtension(), $supportedMimes);
    }

    public function __construct(private UploadedFile $file, private Album $location)
    {
    }

    public function import(): array {
        $image = ImageModel::create([
            'album_id' => $this->location->id
        ]);
        $imageId = $image->id;

        return [
            new ImportImage($this->file->getPathname(), $image),
            new GenerateFullscreen($image),
            new GenerateThumbnail($image),
        ];
    }
}