<?php

namespace Oney\ThreeByFour\Gateway\Response;

use Magento\Checkout\Model\Session;
use Magento\Framework\App\ResponseInterface;
use Magento\Payment\Gateway\Response\HandlerInterface;
use Oney\ThreeByFour\Logger\Logger;

/**
 * Order Response Handler
 * 
 * Handles responses from Oney payment gateway for orders.
 * Processes payment responses and stores them in checkout session.
 * 
 * @package Oney\ThreeByFour\Gateway\Response
 * @version 1.0.0
 * @author Oney
 * @since 1.0.0
 */
class OrderHandler implements HandlerInterface
{
    /**
     * Checkout session instance
     * 
     * @var Session
     * @version 1.0.0
     */
    protected $_checkoutSession;
    
    /**
     * Logger instance
     * 
     * @var Logger
     * @version 1.0.0
     */
    private $_logger;

    /**
     * Constructor
     * 
     * @param Session $checkoutSession Checkout session
     * @param Logger $logger Logger instance
     * @version 1.0.0
     */
    public function __construct(
        Session $checkoutSession,
        Logger $logger
    ) {
        $this->_checkoutSession = $checkoutSession;
        $this->_logger = $logger;
    }

    /**
     * Handle payment response
     * 
     * @param array $handlingSubject Handling subject data
     * @param array $response Response data
     * @return void
     * @version 1.0.0
     */
    public function handle(array $handlingSubject, array $response): void
    {
        $this->_logger->info("[SUCCESS] [CALLBACK] Payment API 1.2 response received: ", [
            'response' => $response
        ]);
        $this->_checkoutSession->setOneyResponse($response);
    }
}
