<?php
/**
 * The Routing Model.
 *
 * @package flo-checkout
 */

namespace Flo_Checkout\Gateways\Shift4_APM\Responses\Models\Payment;

use JsonSerializable;

defined( 'ABSPATH' ) || exit;

/**
 * Class Routing_Model
 */
class Routing_Model implements JsonSerializable {

	/**
	 * The payment processor.
	 *
	 * @var string
	 */
	public string $processor;

	/**
	 * The Payment Processor MID.
	 *
	 * @var string
	 */
	public string $target_mid;

	/**
	 * The Payment Processor Transaction ID.
	 * Used when corresponding with the Payment Processor or when reconciling transactions.
	 *
	 * @var string
	 */
	public string $acquirer_transaction_id;

	/**
	 * The original Response Code as transmitted by the Processor.
	 *
	 * @var string
	 */
	public string $processor_response;

	/**
	 * Routing_Model constructor.
	 *
	 * @param array $routing_data The routing data.
	 */
	public function __construct( array $routing_data ) {
		$this->processor               = $routing_data['processor'];
		$this->target_mid              = $routing_data['target_mid'];
		$this->acquirer_transaction_id = $routing_data['acquirer_transaction_id'];
		$this->processor_response      = $routing_data['processor_response'] ?? '';
	}

	/**
	 * {@inheritDoc}
	 */
	public function jsonSerialize(): array {
		return array(
			'processor'               => $this->processor,
			'target_mid'              => $this->target_mid,
			'acquirer_transaction_id' => $this->acquirer_transaction_id,
			'processor_response'      => $this->processor_response,
		);
	}
}
