<?php
/**
 * Payment Information Management Plugin for Shipping Fields
 * Note: This plugin should NOT handle shipping fields - those belong in the shipping step
 */

namespace PortalPeople\ShippingFields\Plugin;

use Magento\Checkout\Model\PaymentInformationManagement;
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Quote\Api\Data\AddressInterface;
use Psr\Log\LoggerInterface;

class PaymentInformationManagementPlugin
{
    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * Constructor
     *
     * @param LoggerInterface $logger
     */
    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    /**
     * Before save payment information and place order
     *
     * @param PaymentInformationManagement $subject
     * @param int $cartId
     * @param PaymentInterface $paymentMethod
     * @param AddressInterface|null $billingAddress
     * @return array
     */
    public function beforeSavePaymentInformationAndPlaceOrder(
        PaymentInformationManagement $subject,
        $cartId,
        PaymentInterface $paymentMethod,
        AddressInterface $billingAddress = null
    ) {
        $this->logger->info('💳 Payment Plugin: Processing cart ID: ' . $cartId);
        $this->logger->info('💳 Payment method: ' . $paymentMethod->getMethod());
        
        // Note: Shipping fields should be handled in the shipping step, not here
        // This plugin is mainly for debugging the payment process
        
        return [$cartId, $paymentMethod, $billingAddress];
    }
}
