<?php

declare(strict_types=1);

namespace Apexl\Io\Mirror\Hooks;

use Apexl\Io\File\Entities\FileEntity;
use Apexl\Io\Interfaces\AbstractHook;
use Apexl\Io\Mirror\Factories\UploadableFileEntityFactory;
use Apexl\Io\Mirror\Interfaces\UploaderServiceResolverInterface;

final readonly class MirrorFileEntityToCloud implements AbstractHook
{
    public function __construct(private UploaderServiceResolverInterface $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 */
    }
}
