<?php
/**
 * _             _       _
 * | |____      _| | __ _| |__
 * | '_ \ \ /\ / / |/ _` | '_ \
 * | |_) \ V  V /| | (_| | |_) |
 * |_.__/ \_/\_/ |_|\__,_|_.__/.
 *
 * @author    Bwlab di Luigi Massa <info@bwlab.it>
 * @copyright since 2014 Bwlab
 * @license   proprietary
 */

declare(strict_types=1);

namespace Bwlab\Withdrawal\Configuration;

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


use PrestaShop\PrestaShop\Core\Configuration\DataConfigurationInterface;
use PrestaShop\PrestaShop\Core\ConfigurationInterface;

class WithdrawalTextDataConfiguration implements DataConfigurationInterface
{
    public const DEFAULT_DAYS = 'BWWITHDRAWAL_DEFAULT_DAYS';
    public const DATE_REF = 'BWWITHDRAWAL_DATE_REF';
    public const MERCHANT_EMAIL = 'BWWITHDRAWAL_MERCHANT_EMAIL';
    public const NOTICE_IT = 'BWWITHDRAWAL_NOTICE_IT';
    public const NOTICE_EN = 'BWWITHDRAWAL_NOTICE_EN';
    public const ENABLED = 'BWWITHDRAWAL_ENABLED';

    public function __construct(private readonly ConfigurationInterface $configuration)
    {
    }

    public function getConfiguration(): array
    {
        return [
            self::DEFAULT_DAYS => (int) $this->configuration->get(self::DEFAULT_DAYS),
            self::DATE_REF => $this->configuration->get(self::DATE_REF) ?: 'order',
            self::MERCHANT_EMAIL => $this->configuration->get(self::MERCHANT_EMAIL),
            self::NOTICE_IT => $this->configuration->get(self::NOTICE_IT),
            self::NOTICE_EN => $this->configuration->get(self::NOTICE_EN),
            self::ENABLED => (bool) $this->configuration->get(self::ENABLED),
        ];
    }

    public function updateConfiguration(array $configuration): array
    {
        $this->configuration->set(self::DEFAULT_DAYS, (int) $configuration[self::DEFAULT_DAYS]);
        $this->configuration->set(self::DATE_REF, $configuration[self::DATE_REF]);
        $this->configuration->set(self::MERCHANT_EMAIL, $configuration[self::MERCHANT_EMAIL]);
        $this->configuration->set(self::NOTICE_IT, $configuration[self::NOTICE_IT]);
        $this->configuration->set(self::NOTICE_EN, $configuration[self::NOTICE_EN]);
        $this->configuration->set(self::ENABLED, (int) $configuration[self::ENABLED]);

        return [];
    }

    public function validateConfiguration(array $configuration): bool
    {
        return isset(
            $configuration[self::DEFAULT_DAYS],
            $configuration[self::DATE_REF],
            $configuration[self::MERCHANT_EMAIL]
        );
    }
}
