<?php
class ZATCA implements iTransQR
{
	protected $data = [];

	function __construct(array $trans = [])
	{
		$this->set_data($trans);
	}

	public function set_data(array $trans = [])
	{
		if (empty($trans))
		{
			return $this;
		}

		require_once("Tag.php");

		$this->data = array(
			new Tag(1, !empty($trans['company']['compName']) ? $trans['company']['compName'] : ''),
			new Tag(2, !empty($trans['company']['gstin']) ? $trans['company']['gstin'] : ''),
			new Tag(3, !empty($trans['_tDate']) ? $trans['_tDate'] : ''),
			new Tag(4, !empty($trans['totAmount']) ? $trans['totAmount'] : 0),
			new Tag(5, !empty($trans['totTax']) ? $trans['totTax'] : 0)
		);


        return $this;
	}

	public function toTLV()
	{
		return implode('', array_map(function ($tag) {
			return (string) $tag;
		}, $this->data));
	}

	public function toBase64()
	{
		return base64_encode($this->toTLV());
	}

	public function get_content(array $trans = [])
	{
		return $this->set_data($trans)->toBase64();
	}

	public function __toString()
	{
		return $this->get_content();
	}
}
