<?php
/**
 * Shift4 APM response factory.
 *
 * @package  flo-checkout
 */

namespace Flo_Checkout\Gateways\Shift4_APM\Responses;

use Exception;
use Flo_Checkout\Gateways\Shift4_APM\Abstract_APM_Gateway;
use Flo_Checkout\Gateways\Shift4_APM\Requests\Models\Gateway_Request_Response_Model;
use Flo_Checkout\Gateways\Shift4_APM\Requests\Models\Request_Response_Model;
use WC_Order;

defined( 'ABSPATH' ) || exit;

/**
 * Credorax Credorax response factory model.
 */
class Response_Factory_Gateway extends Response_Factory {

	/**
	 * Response_Factory constructor.
	 *
	 * @param Abstract_APM_Gateway $gateway Gateway.
	 */
	public function __construct( private readonly Abstract_APM_Gateway $gateway ) {
		parent::__construct();
	}

	/**
	 * Create a response model.
	 *
	 * @param Gateway_Request_Response_Model|Request_Response_Model $response_model Response data.
	 * @param WC_Order|null                                         $order          Order object.
	 *
	 * @return Abstract_Response_Gateway
	 * @throws Exception If the response type is not supported.
	 */
	public function create(
		Gateway_Request_Response_Model|Request_Response_Model $response_model,
		?WC_Order $order = null
	): Abstract_Response_Gateway {
		$class_name = $this->get_class_name( $response_model );

		return new $class_name( $this->gateway, $response_model, $order );
	}
}
