<?php
/**
 * TrackBee order client details data.
 *
 * @package TrackBee_Connect
 * @subpackage Dto
 * @version 1.0.0
 */

namespace TrackBee_Connect\Dto;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * The order client details data for a TrackBee order.
 *
 * @version 1.0.0
 * @package TrackBee_Connect
 * @subpackage Dto
 */
class TB_Order_Client_Details_Dto implements \JsonSerializable {

	/**
	 * The IP address of the client.
	 */
	protected string $ip;
  /**
   * A session identifier.
   * Usually this is an identifier generated by a cookie in the client.
   */
  protected ?string $sessionId;
  /**
   * The height of the browser window.
   */
  protected ?string $browserHeight;

  /**
   * The width of the browser window.
   */
  protected ?string $browserWidth;

  /**
   * The browsers useragent.
   */
  protected string $userAgent;

	/**
	 * Constructor.
	 *
	 * @param string $ip The IP address of the client.
	 * @param ?string $sessionId A session identifier.
	 * @param ?string $browserHeight The height of the browser window.
	 * @param ?string $browserWidth The width of the browser window.
	 * @param string $userAgent The browsers useragent.
	 */
	public function __construct( string $ip, ?string $sessionId, ?string $browserHeight, ?string $browserWidth, string $userAgent ) {
		$this->ip = $ip;
		$this->sessionId = $sessionId;
		$this->browserHeight = $browserHeight;
		$this->browserWidth = $browserWidth;
		$this->userAgent = $userAgent;
	}

	/**
	 * Serialize the object to JSON.
	 *
	 * @return object
	 */
	public function jsonSerialize(): object {
		return (object) get_object_vars( $this );
	}

	/**
	 * Construct a TB_Order_Client_Details_Dto with dummy data.
	 *
	 * @return TB_Order_Client_Details_Dto
	 */
	public static function get_dummy_data(): TB_Order_Client_Details_Dto
	{
		return new TB_Order_Client_Details_Dto(
			'::1',
			null,
			null,
			null,
			'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
		);
	}

}
