<?php

declare(strict_types=1);

namespace Apexl\Io\MirrorS3\Hooks;

use Apexl\Io\Interfaces\HookInterface;
use Apexl\Io\Mirror\Interfaces\UploaderServiceResolverInterface;
use Apexl\Io\MirrorS3\Services\S3UploaderService;
use Arrayy\Type\StringCollection;

/**
 * Registers `s3` as an alias for this driver's uploader, so an install can set
 * `MIRROR_DEFAULT_UPLOADER=s3` rather than name a class in its environment —
 * and not have to change every environment when that class moves.
 */
final readonly class AddS3Alias implements HookInterface
{
    public static function hooks(): array
    {
        return [
            UploaderServiceResolverInterface::HOOK__UPLOADER_SERVICE_ALIASES,
        ];
    }

    public function __invoke(StringCollection $aliases): StringCollection
    {
        // In place: the resolver memoises the collection it passed in, so
        // returning a new one would re-fire the whole chain on every call.
        $aliases->set('s3', S3UploaderService::class);

        return $aliases;
    }
}
