<?php

declare(strict_types=1);

namespace apexl\Io\modules\mirror\Hook;

use apexl\Io\interfaces\AbstractHook;
use apexl\Io\modules\file\entities\fileEntity;
use apexl\Io\modules\mirror\Factory\UploadableFileEntityFactory;
use apexl\Io\modules\mirror\Helper\UploaderServiceResolver;

final readonly class MirrorFileEntityToCloud implements AbstractHook
{
    public function __construct(private UploaderServiceResolver $uploaderResolver, private UploadableFileEntityFactory $uploadableFileEntityFactory) {}

    public function hooks(): array
    {
        return [
            fileEntity::POST_STORE_WITH_RELATIONS_HOOK,
        ];
    }

    public function __invoke(fileEntity $file): void
    {

        $uploadable = $this->uploadableFileEntityFactory->make($file);
        $entityClass = $file->getRelatedEntityClass();


        $uploader = $this->uploaderResolver->resolve($entityClass ?? '');
        $uploader->upload($uploadable);

        /** @TODO remove original file */
    }
}
