<?php
/**
 * Payment details model.
 *
 * @package flo-checkout
 */

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

use JsonSerializable;

defined( 'ABSPATH' ) || exit;

/**
 * Payment details model.
 */
class Payment_Details_Model implements JsonSerializable {

	/**
	 * The card number (Primary Account Number). Redacted.
	 *
	 * @var string
	 */
	public string $pan;

	/**
	 * The card type.
	 *
	 * @var string
	 */
	public string $card_type;

	/**
	 * The expiry month.
	 *
	 * @var string
	 */
	public string $expiry_month;

	/**
	 * The expiry year.
	 *
	 * @var string
	 */
	public string $expiry_year;

	/**
	 * Initial transaction ID.
	 * Received as part of the initial transaction response parameters.
	 * Must be sent for every subsequent "merchant initiated transaction".
	 *
	 * @var string
	 */
	public string $initial_transaction_id;

	/**
	 * Authorization code.
	 *
	 * @var string
	 */
	public string $authorization_code;

	/**
	 * Retrieval Reference Number.
	 * The transaction's Retrieval Reference Number (RRN).
	 * The RRN may be provided by the processor as an additional identifier of the transaction.
	 * Every refund transaction will receive a unique RRN, different from the initial transaction RRN.
	 *
	 * @var int
	 */
	public int $rrn;

	/**
	 * The source type.
	 *
	 * @var int
	 */
	public int $source_type;

	/**
	 * The cardholder name.
	 *
	 * @var string
	 */
	public string $cardholder_name;

	/**
	 * Recurring.
	 *
	 * @var int
	 */
	public int $recurring;

	/**
	 * Payment account reference.
	 *
	 * @var string
	 */
	public string $payment_account_reference;

	/**
	 * Payment_Details_Model constructor.
	 *
	 * @param array $payment_details Payment details.
	 */
	public function __construct( array $payment_details ) {
		$this->pan                       = $payment_details['pan'] ?? '';
		$this->card_type                 = $payment_details['card_type'];
		$this->expiry_month              = $payment_details['expiry_month'] ?? '';
		$this->expiry_year               = $payment_details['expiry_year'] ?? '';
		$this->initial_transaction_id    = $payment_details['initial_transaction_id'] ?? '';
		$this->authorization_code        = $payment_details['authorization_code'];
		$this->rrn                       = $payment_details['rrn'];
		$this->source_type               = $payment_details['source_type'];
		$this->cardholder_name           = $payment_details['cardholder_name'];
		$this->recurring                 = $payment_details['recurring'];
		$this->payment_account_reference = $payment_details['payment_account_reference'] ?? '';
	}

	/**
	 * {@inheritDoc}
	 */
	public function jsonSerialize(): array {
		return array(
			'pan'                       => $this->pan,
			'card_type'                 => $this->card_type,
			'expiry_month'              => $this->expiry_month,
			'expiry_year'               => $this->expiry_year,
			'initial_transaction_id'    => $this->initial_transaction_id,
			'authorization_code'        => $this->authorization_code,
			'rrn'                       => $this->rrn,
			'source_type'               => $this->source_type,
			'cardholder_name'           => $this->cardholder_name,
			'recurring'                 => $this->recurring,
			'payment_account_reference' => $this->payment_account_reference,
		);
	}
}
