<?php
/**
 * TrackBee event data base dto.
 *
 * @package TrackBee_Connect
 * @subpackage Dto
 * @version 1.1.0
 */

namespace TrackBee_Connect\Dto;

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

/**
 * Abstract base class for TrackBee event data.
 *
 * @version 1.1.0
 * @package TrackBee_Connect
 * @subpackage Dto
 */
class TB_Event_Data_Base_Dto implements \JsonSerializable {

	/**
	 * Event specific data.
	 *
	 * @var TB_Event_Data_Dto
	 */
	protected TB_Event_Data_Dto $data;

	/**
	 * Unique identifier for this event.
	 *
	 * @var string
	 */
	protected string $id;

	/**
	 * Identifier that stays the same for multiple events from the same client.
	 *
	 * @var string
	 */
	protected string $clientId;

	/**
	 * Timestamp when the event occurred.
	 *
	 * @var string
	 */
	protected string $timestamp;

	/**
	 * Browser context data.
	 *
	 * @var TB_Event_Data_Context_Dto
	 */
	protected TB_Event_Data_Context_Dto $context;

	/**
	 * Pinterest click identifier, when available.
	 *
	 * @var ?string
	 */
	protected ?string $epik;

	/**
	 * Facebook click identifier, when available.
	 *
	 * @var ?string
	 */
	protected ?string $fbc;

	/**
	 * Facebook browser identifier, when available.
	 *
	 * @var ?string
	 */
	protected ?string $fbp;

	/**
	 * Tiktok click identifier, when available.
	 *
	 * @var ?string
	 */
	protected ?string $ttclid;

	/**
	 * Tiktok browser identifier, when available.
	 *
	 * @var ?string
	 */
	protected ?string $ttp;

	/**
	 * Google click identifier, when available.
	 *
	 * @var ?string
	 */
	protected ?string $gclid;

	/**
	 * Google WBRAID parameter, when available.
	 *
	 * @var ?string
	 */
	protected ?string $wbraid;

	/**
	 * Google GBRAID parameter, when available.
	 *
	 * @var ?string
	 */
	protected ?string $gbraid;

	/**
	 * Klaviyo click identifier, when available.
	 *
	 * @var ?string
	 */
	protected ?string $kx;

	/**
	 * Source found as utm parameter.
	 *
	 * @var ?string
	 */
	protected ?string $utmSource;

	/**
	 * Campaign id found as utm parameter.
	 *
	 * @var ?string
	 */
	protected ?string $utmCampaign;

	/**
	 * Ad group id found as utm parameter.
	 *
	 * @var ?string
	 */
	protected ?string $utmAdGroup;

	/**
	 * Ad id found as utm parameter.
	 *
	 * @var ?string
	 */
	protected ?string $utmAd;

	/**
	 * Google Ads consent status for user data.
	 *
	 * @var string
	 */
	protected string $userDataConsent;

	/**
	 * Google Ads consent status for ad personalization.
	 *
	 * @var string
	 */
	protected string $personalizationConsent;

	/**
	 * The id generated by Trackbee and stored in the local storage.
	 *
	 * @var string
	 */
	protected string $tbId;

	/**
	 * Constructor.
	 *
	 * @param string $id Unique identifier for this event.
	 * @param string $clientId Identifier that stays the same for multiple events from the same client.
	 * @param string $timestamp Timestamp when the event occurred.
	 * @param TB_Event_Data_Context_Dto $context Browser context data.
	 * @param ?string $epik Pinterest click identifier, when available.
	 * @param ?string $fbc Facebook click identifier, when available.
	 * @param ?string $fbp Facebook browser identifier, when available.
	 * @param ?string $ttclid Tiktok click identifier, when available.
	 * @param ?string $ttp Tiktok browser identifier, when available.
	 * @param ?string $gclid Google click identifier, when available.
	 * @param ?string $wbraid Google WBRAID parameter, when available.
	 * @param ?string $gbraid Google GBRAID parameter, when available.
	 * @param ?string $kx Klaviyo click identifier, when available.
	 * @param ?string $utmSource Source found as utm parameter.
	 * @param ?string $utmCampaign Campaign id found as utm parameter.
	 * @param ?string $utmAdGroup Ad group id found as utm parameter.
	 * @param ?string $utmAd Ad id found as utm parameter.
	 * @param ?string $userDataConsent Google Ads consent status for user data.
	 * @param ?string $personalizationConsent Google Ads consent status for ad personalization.
	 * @param string $tbId The id generated by Trackbee and stored in the local storage.
	 */
	public function __construct(
		string $id,
		string $clientId,
		string $timestamp,
		TB_Event_Data_Context_Dto $context,
		?string $epik,
		?string $fbc,
		?string $fbp,
		?string $ttclid,
		?string $ttp,
		?string $gclid,
		?string $wbraid,
		?string $gbraid,
		?string $kx,
		?string $utmSource,
		?string $utmCampaign,
		?string $utmAdGroup,
		?string $utmAd,
		?string $userDataConsent,
		?string $personalizationConsent,
		string $tbId
	) {
		$this->id = $id;
		$this->clientId = $clientId;
		$this->timestamp = $timestamp;
		$this->context = $context;
		$this->epik = empty( $epik ) ? null : $epik;
		$this->fbc = empty( $fbc ) ? null : $fbc;
		$this->fbp = empty( $fbp ) ? null : $fbp;
		$this->ttclid = empty( $ttclid ) ? null : $ttclid;
		$this->ttp = empty( $ttp ) ? null : $ttp;
		$this->gclid = empty( $gclid ) ? null : $gclid;
		$this->wbraid = empty( $wbraid ) ? null : $wbraid;
		$this->gbraid = empty( $gbraid ) ? null : $gbraid;
		$this->kx = empty( $kx ) ? null : $kx;
		$this->utmSource = empty( $utmSource ) ? null : $utmSource;
		$this->utmCampaign = empty( $utmCampaign ) ? null : $utmCampaign;
		$this->utmAdGroup = empty( $utmAdGroup ) ? null : $utmAdGroup;
		$this->utmAd = empty( $utmAd ) ? null : $utmAd;
		$this->userDataConsent = empty( $userDataConsent ) ? 'GRANTED' : $userDataConsent;
		$this->personalizationConsent = empty( $personalizationConsent ) ? 'GRANTED' : $personalizationConsent;
		$this->tbId = $tbId;
	}

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

	/**
	 * Get the event id.
	 *
	 * @return string
	 */
	public function get_id(): string { return $this->id; }

	/**
	 * Get the client id.
	 *
	 * @return string
	 */
	public function get_client_id(): string { return $this->clientId; }

	/**
	 * Get the timestamp.
	 *
	 * @return string
	 */
	public function get_timestamp(): string { return $this->timestamp; }

	/**
	 * Get the context.
	 *
	 * @return TB_Event_Data_Context_Dto
	 */
	public function get_context(): TB_Event_Data_Context_Dto { return $this->context; }

	/**
	 * Get the epik.
	 *
	 * @return ?string
	 */
	public function get_epik(): ?string { return $this->epik; }

	/**
	 * Get the fbc.
	 *
	 * @return ?string
	 */
	public function get_fbc(): ?string { return $this->fbc; }

	/**
	 * Get the fbp.
	 *
	 * @return ?string
	 */
	public function get_fbp(): ?string { return $this->fbp; }

	/**
	 * Get the ttclid.
	 *
	 * @return ?string
	 */
	public function get_ttclid(): ?string { return $this->ttclid; }

	/**
	 * Get the ttp.
	 *
	 * @return ?string
	 */
	public function get_ttp(): ?string { return $this->ttp; }

	/**
	 * Get the gclid.
	 *
	 * @return ?string
	 */
	public function get_gclid(): ?string { return $this->gclid; }

	/**
	 * Get the wbraid.
	 *
	 * @return ?string
	 */
	public function get_wbraid(): ?string { return $this->wbraid; }

	/**
	 * Get the gbraid.
	 *
	 * @return ?string
	 */
	public function get_gbraid(): ?string { return $this->gbraid; }

	/**
	 * Get the kx.
	 *
	 * @return ?string
	 */
	public function get_kx(): ?string { return $this->kx; }

	/**
	 * Get the utmSource.
	 *
	 * @return ?string
	 */
	public function get_utm_source(): ?string { return $this->utmSource; }

	/**
	 * Get the utmCampaign.
	 *
	 * @return ?string
	 */
	public function get_utm_campaign(): ?string { return $this->utmCampaign; }

	/**
	 * Get the utmAdGroup.
	 *
	 * @return ?string
	 */
	public function get_utm_ad_group(): ?string { return $this->utmAdGroup; }

	/**
	 * Get the utmAd.
	 *
	 * @return ?string
	 */
	public function get_utm_ad(): ?string { return $this->utmAd; }

	/**
	 * Get the userDataConsent.
	 *
	 * @return string
	 */
	public function get_user_data_consent(): string { return $this->userDataConsent; }

	/**
	 * Get the personalizationConsent.
	 *
	 * @return string
	 */
	public function get_personalization_consent(): string { return $this->personalizationConsent; }

	/**
	 * Get the tbId.
	 *
	 * @return string
	 */
	public function get_tb_id(): string { return $this->tbId; }

	/**
	 * Set the event data.
	 *
	 * @return void
	 */
	public function set_data( TB_Event_Data_Dto $data ) {
		$this->data = $data;
	}

}
