<?php
/**
 * Elite Notification Item Library
 *
 * @package Elite_Notification_Lite\Libs
 */

namespace Elite_Notification_Lite\Libs;

use Cassandra\Date;
use Elite_Notification_Lite\Modules\Elite_Notification_Settings;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Elite_Notification_Item
 *
 * @package Elite_Notification_Lite\Libs
 */
class Elite_Notification_Item {
	/**
	 * Its property id
	 *
	 * @var mixed
	 */
	public $id;
	/**
	 * Its property img
	 *
	 * @var mixed
	 */
	public $img;
	/**
	 * Its property des
	 *
	 * @var mixed
	 */
	public $des;
	/**
	 * Its property nt_by
	 *
	 * @var mixed
	 */
	public $nt_by;
	/**
	 * Its property typ
	 *
	 * @var mixed
	 */
	public $typ;
	/**
	 * Its property op_date
	 *
	 * @var Date
	 */
	public $op_date;
	/**
	 * Its property op_timestamp
	 *
	 * @var int
	 */
	public $op_timestamp;
	/**
	 * Its property view_style
	 *
	 * @var mixed
	 */
	public $view_style;
	/**
	 * Its property link_url
	 *
	 * @var string
	 */
	public $link_url = '';
	/**
	 * Its property click_url
	 *
	 * @var string
	 */
	public $click_url = '';
	/**
	 * Its property source_id
	 *
	 * @var mixed
	 */
	public $source_id;

	/**
	 * The   toString is generated by appsbd
	 *
	 * @return string
	 */
	public function __toString() {
		return serialize( $this );
	}

	/**
	 * The set id is generated by appsbd
	 */
	public function set_id() {
		if ( empty( $this->id ) ) {
			$this->id = hash( 'crc32b', $this );
		}
	}

	/**
	 * The set click link is generated by appsbd
	 */
	public function set_click_link() {
		if ( empty( $this->link_url ) ) {
			return;
		}
		$this->click_url = get_site_url() . "?_siid={$this->source_id}&_aasanl=" . urlencode( $this->link_url );
	}

	/**
	 * The set time is generated by appsbd
	 */
	public function set_time() {
		$this->op_date = sprintf(
			Elite_Notification_Settings::get_module_instance()->__( '%s ago' ),
			human_time_diff(
				$this->op_timestamp,
				current_time( 'timestamp' )
			)
		);
	}
}
