<?php declare(strict_types=1);

namespace App\Engine\Settings\Sections\Content;

/**
 * @extends \App\Engine\Settings\Sections\SettingsSection<\App\Engine\Settings\Sections\Content\HomeHero>
 */
readonly class HomeHeroSettingsSection extends \App\Engine\Settings\Sections\SettingsSection
{

    public function getGroup(): \App\Engine\Settings\Groups
    {
        return \App\Engine\Settings\Groups::Content;
    }

    public function getPriority(): int
    {
        return 10;
    }

    public function getTitle(): string
    {
        return $this->translator->trans("admin.settings.sections.home-hero.section-title");
    }

    public function getId(): string
    {
        return "home-hero";
    }

    protected function getObjectClassName(): string
    {
        return \App\Engine\Settings\Sections\Content\HomeHero::class;
    }

    protected function processFormData(\Symfony\Component\Form\FormInterface $form, mixed $data): \Symfony\Component\Form\FormInterface
    {
        $this->storageUploader->processFile(
            $form,
            fieldName: "desktopImage",
            recordTitle: "hero-image",
            setFile: fn(string $imagePath) => $data->desktopImage = $imagePath,
            storageLocation: self::SETTINGS_STORAGE_LOCATION_PREFIX,
        );
        $this->storageUploader->processFile(
            $form,
            fieldName: "mobileImage",
            recordTitle: "hero-image",
            setFile: fn(string $imagePath) => $data->mobileImage = $imagePath,
            storageLocation: self::SETTINGS_STORAGE_LOCATION_PREFIX,
        );

        return \App\Engine\Settings\Sections\SettingsSection::processFormData($this->formFactory->create($this->getFormClassName(), $data), $data);
    }

    protected function getFormClassName(): string
    {
        return \App\Engine\Settings\Sections\Content\HomeHeroForm::class;
    }

}