<?php

namespace Tricks\MediaLibraryOverrides;

use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use Spatie\MediaLibrary\Conversions\Events\ConversionHasBeenCompletedEvent;
use Spatie\MediaLibrary\MediaCollections\Events\MediaHasBeenAddedEvent;
use Spatie\MediaLibrary\ResponsiveImages\ResponsiveImageGenerator;
use Tricks\MediaLibraryOverrides\Listeners\ImageDimensionListener;
use Tricks\MediaLibraryOverrides\ResponsiveImages\WidthOnlyResponsiveImageGenerator;

class MediaLibraryOverridesServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->bind(ResponsiveImageGenerator::class, WidthOnlyResponsiveImageGenerator::class);
    }

    public function boot(): void
    {
        Event::listen(
            [
                MediaHasBeenAddedEvent::class,
                ConversionHasBeenCompletedEvent::class,
            ],
            ImageDimensionListener::class
        );
    }
}
