<?php

namespace Magento\Billdesk\Model;

use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Billdesk\Model\PaymentMethod;
use Magento\Checkout\Model\ConfigProviderInterface;

class ConfigProvider implements ConfigProviderInterface
{
    /**
     * @var string[]
     */
    protected $methodCode = PaymentMethod::METHOD_CODE;

    /**
     * @var \Magento\Billdesk\Model\Config
     */
    protected $config;

    /**
     * @var \Magento\Checkout\Model\Session
     */
    protected $checkoutSession;

    /**
     * @var \Magento\Customer\Model\Session
     */
    protected $customerSession;

    /**
     * Url Builder
     *
     * @var \Magento\Framework\Url
     */
    protected $urlBuilder;
    protected $assetRepo;
    protected $request;
    protected $logger;
    protected $method;


    /**
     * @param \Magento\Checkout\Model\Session $checkoutSession
     * @param \Magento\Customer\Model\Session $customerSession
     * @param \Magento\Framework\Url $urlBuilder
     */
    public function __construct(
        \Magento\Framework\View\Asset\Repository $assetRepo,
        \Magento\Framework\App\RequestInterface $request,
        \Magento\Framework\Url $urlBuilder,
        \Psr\Log\LoggerInterface $logger,
        PaymentHelper $paymentHelper,
        \Magento\Billdesk\Model\Config $config,
        \Magento\Checkout\Model\Session $checkoutSession,
        \Magento\Customer\Model\Session $customerSession
    ) {
        $this->assetRepo = $assetRepo;
        $this->request = $request;
        $this->urlBuilder = $urlBuilder;
        $this->logger = $logger;
        $this->methodCode = PaymentMethod::METHOD_CODE;
        $this->method = $paymentHelper->getMethodInstance(PaymentMethod::METHOD_CODE);
        $this->config = $config;
        $this->checkoutSession = $checkoutSession;
        $this->customerSession = $customerSession;
    }

    /**
     * @return array|void
     */
    public function getConfig()
    {
        if (!$this->config->isActive()) {
            return [];
        }

        $config = [
            'payment' => [
                'billdesk' => [
                    'merchant_id' => $this->config->getMerchantId(),
                    //'merchant_key'    => $this->config->getMerchantKey(),
                    'jose_encryption_key' => $this->config->getJoseEncryptionKey(),
                    'jose_signing_key' => $this->config->getJoseSigningKey(),
                    'client_id' => $this->config->getClientId(),
                    'key_id' => $this->config->getKeyId(),
                    'merchant_logo'  => $this->config->getMerchantLogo(),
                    'item_code'  => $this->config->getItemCode(),
                    'child_window' => $this->config->getChildWindow(),
                    'retry_count' => $this->config->getRetryCount(),
                    'payment_category' => $this->config->getPaymentCatogery(),
                    'env_variable' => $this->config->getEnvVariable(),
                    'iso_currency' => $this->config->getISOCurrency(),
                ],
            ],
        ];

        return $config;
    }
}
