<?php
/**
 * File: GetQueryRequest.php
 * Year: 2023
 */

namespace Tami\WooCommerce;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( '\Tami\WooCommerce\GetQueryRequest' ) ) {
	class GetQueryRequest {
		private string $orderId;
		private $isTransactionDetail = null;
		public $securityHash;


		public function generateSecurityHash( $merchantId, $terminalId, $secretKey, $fixedKidValue, $fixedKValue ) {
			$requestBody = [
				'orderId'             => $this->orderId,
				'isTransactionDetail' => (bool) $this->isTransactionDetail,
			];

			if ( ! class_exists( 'Tami\WooCommerce\HashGenerator' ) ) {
				include dirname( __FILE__, 2 ) . '/HashGenerator.php';
			}

			$HashGenerator = new HashGenerator( $merchantId, $terminalId, $secretKey, $fixedKidValue, $fixedKValue );
			$hash          = $HashGenerator->generateJWKSignature( $requestBody );

			$this->setSecurityHash( $hash );
		}

		public function setSecurityHash( $securityHash ) {
			$this->securityHash = $securityHash;

			return $this;
		}

		public function setOrderId( string $orderId ): GetQueryRequest {
			$this->orderId = $orderId;

			return $this;
		}

		public function setIsTransactionDetail( $isTransactionDetail ): GetQueryRequest {
			$this->isTransactionDetail = $isTransactionDetail;

			return $this;
		}

		public function get(): object {
			return (object) [
				'orderId'             => $this->orderId,
				'isTransactionDetail' => $this->isTransactionDetail,
				'securityHash'        => $this->securityHash,
			];
		}
	}
}
