<?php
/**
 * 2026 Paysera
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@prestashop.com so we can send you a copy immediately.
 *
 * @author Paysera <plugins@paysera.com>
 * @copyright 2026 Paysera
 * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
 * International Registered Trademark & Property of Paysera
 */

declare(strict_types=1);

namespace Paysera\PrestashopPayments\Form;

use PrestaShop\PrestaShop\Core\Form\FormDataProviderInterface;

if (!defined('_PS_VERSION_')) {
    exit;
}

/**
 * Provides data for PaymentSettingsFormType.
 * Acts as an adapter between PrestaShop Form Handler and PaymentSettingsDataConfiguration.
 */
final class PaymentSettingsFormDataProvider implements FormDataProviderInterface
{
    private PaymentSettingsDataConfiguration $dataConfiguration;

    public function __construct(PaymentSettingsDataConfiguration $dataConfiguration)
    {
        $this->dataConfiguration = $dataConfiguration;
    }

    /**
     * Get current form data from configuration.
     *
     * @return array{
     *     enable_payments: bool,
     *     payment_window_mode: string,
     *     status_awaiting_confirmation: string,
     *     status_confirmed_payment: string,
     *     status_awaiting_payment: string,
     *     payment_title: string
     * }
     */
    public function getData(): array
    {
        return $this->dataConfiguration->getConfiguration();
    }

    /**
     * Save form data to configuration.
     *
     * @param array{
     *     enable_payments?: bool,
     *     payment_window_mode?: string,
     *     status_awaiting_confirmation?: string,
     *     status_confirmed_payment?: string,
     *     status_awaiting_payment?: string,
     *     payment_title?: string
     * } $data
     *
     * @return list<string> List of error messages, empty if successful
     */
    public function setData(array $data): array
    {
        return $this->dataConfiguration->updateConfiguration($data);
    }
}
