<?php

namespace Sibs\Sibs\Controller\Payment;

use DateTime;
use Sibs\Sibs\Model\SibsConstants;

class Pbl extends SibsPayment
{
    /**
     * @param \Magento\Framework\App\Action\Context $context,
     * @param \Magento\Checkout\Model\Session $checkoutSession,
     * @param \Sibs\Sibs\Helper\DataHelper $sibsHelper,
     * @param \Sibs\Sibs\Model\SibsOrderFactory $sibsOrderFactory,
     * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
     */
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Checkout\Model\Session $checkoutSession,
        \Sibs\Sibs\Helper\DataHelper $sibsHelper,
        \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
    ) {
        parent::__construct(
            $context,
            $checkoutSession,
            $sibsHelper,
            $resultJsonFactory,
            SibsConstants::SIBS_API_METHOD_PAY_BY_LINK_KEVIN,
            SibsConstants::SIBS_PAYMENT_METHOD_PAY_BY_LINK
        );
    }

    /**
     * Get Transaction Data
     *
     * @return array
     */
    protected function transactionData()
    {
        $paymentMethod = [$this->_paymentMethod];
        $paymentType   = (string) $this->_sibsHelper->getPBLPaymentType();

        $expire = new DateTime();

        $sibs_payment_expiration_date_value = (int) '1';
        $sibs_payment_expiration_date_unit  = (string) 'day';
        $abs_number                         = abs(intval($sibs_payment_expiration_date_value));
        $date_offset                        = '+' . $abs_number . ' ' . $sibs_payment_expiration_date_unit;

        $expire->modify($date_offset);

        return array_merge_recursive($this->getCheckoutData($paymentMethod, $paymentType), [
            'transaction' => [
                'payByLink' => [
                    'expirationDateTime'     => $expire->format(SibsConstants::DATE_FORMAT_API),
                    'linkExpirationDateTime' => $expire->format(SibsConstants::DATE_FORMAT_API),
                ],
            ],
        ]);
    }
}
