<?php
/**
 * Receipt Voucher model.
 *
 * @package northmill-online-shared
 */

declare(strict_types=1);

namespace Northmill_Online_Shared\Abstracts\Hub_API\Models\Receipts;

use JsonSerializable;

/**
 * Voucher model.
 */
class Receipt_Voucher_Model implements JsonSerializable {
	/**
	 * Voucher ID.
	 *
	 * @var string|null
	 */
	protected string|null $Id;

	/**
	 * Update on existing voucher.
	 *
	 * @var bool|null
	 */
	protected bool|null $UpdateOnExisting;

	/**
	 * Supporting number.
	 *
	 * @var int|null
	 */
	protected int|null $SupportingNumber;

	/**
	 * Voucher number.
	 *
	 * @var string|null
	 */
	protected string|null $VoucherNumber;

	/**
	 * Voucher series.
	 *
	 * @var string|null
	 */
	protected string|null $VoucherSeries;

	/**
	 * Whether the voucher is deleted.
	 *
	 * @var bool
	 */
	protected bool $IsDeleted;

	/**
	 * State of the voucher.
	 * Default: 'Pending'
	 *
	 * @var string
	 */
	protected string $State;

	/**
	 * Reason for error, if any.
	 *
	 * @var string|null
	 */
	protected string|null $ErrorReason;

	/**
	 * Whether the voucher is bookkept.
	 *
	 * @var bool
	 */
	protected bool|null $IsBookkept;

	/**
	 * Voucher sync reference.
	 *
	 * @var string|null
	 */
	protected string|null $VoucherSyncReference;

	/**
	 * Voucher sync time.
	 *
	 * @var string|null
	 */
	protected string|null $VoucherSyncTime;

	/**
	 * Cashier serial number.
	 *
	 * @var string|null
	 */
	protected string|null $CashierSerialNumber;

	/**
	 * Voucher date.
	 * Format: Y-m-d\\TH:i:s
	 *
	 * @var string|null
	 */
	protected string|null $VoucherDate;

	/**
	 * Voucher text.
	 *
	 * @var string
	 */
	protected string $VoucherText;

	/**
	 * Project.
	 *
	 * @var string|null
	 */
	protected string|null $Project;

	/**
	 * Cost center.
	 *
	 * @var string|null
	 */
	protected string|null $CostCenter;

	/**
	 * Reference number.
	 *
	 * @var string
	 */
	protected string $ReferenceNumber;

	/**
	 * Reference type.
	 * Default: 'WebOrder'
	 *
	 * @var string
	 */
	protected string $ReferenceType;

	/**
	 * Voucher rows.
	 *
	 * @var Receipt_Voucher_Row_Model[]
	 */
	protected array $Rows;

	/**
	 * Time the voucher was created.
	 *
	 * @var string|null
	 */
	protected string|null $CreatedTime;

	/**
	 * Time the voucher was modified.
	 *
	 * @var string|null
	 */
	protected string|null $ModifiedTime;

	public function __construct(
		string $reference_number,
		array $rows,
		?string $voucher_date,
		string $voucher_text = '',
		string $id = null,
		bool $is_deleted = false,
		string $state = 'Pending',
		string $reference_type = 'WebOrder',
		bool $update_on_existing = null,
		?int $supporting_number = null,
		string $voucher_number = null,
		string $voucher_series = null,
		string $error_reason = null,
		bool $is_bookkept = null,
		string $voucher_sync_reference = null,
		string $voucher_sync_time = null,
		string $cashier_serial_number = null,
		string $project = null,
		string $cost_center = null,
		string $created_time = null,
		string $modified_time = null
	) {
		$this->Id                   = $id;
		$this->UpdateOnExisting     = $update_on_existing;
		$this->SupportingNumber     = $supporting_number;
		$this->VoucherNumber        = $voucher_number;
		$this->VoucherSeries        = $voucher_series;
		$this->IsDeleted            = $is_deleted;
		$this->State                = $state;
		$this->ErrorReason          = $error_reason;
		$this->IsBookkept           = $is_bookkept;
		$this->VoucherSyncReference = $voucher_sync_reference;
		$this->VoucherSyncTime      = $voucher_sync_time;
		$this->CashierSerialNumber  = $cashier_serial_number;
		$this->VoucherDate          = $voucher_date;
		$this->VoucherText          = $voucher_text;
		$this->Project              = $project;
		$this->CostCenter           = $cost_center;
		$this->ReferenceNumber      = $reference_number;
		$this->ReferenceType        = $reference_type;
		$this->Rows                 = $rows;
		$this->CreatedTime          = $created_time;
		$this->ModifiedTime         = $modified_time;
	}

	/**
	 * Get the voucher rows.
	 *
	 * @return Receipt_Voucher_Row_Model[]
	 */
	public function get_rows(): array {
		return $this->Rows;
	}

	public function jsonSerialize(): array {
		return array(
			'Id'                   => $this->Id,
			'UpdateOnExisting'     => $this->UpdateOnExisting,
			'SupportingNumber'     => $this->SupportingNumber,
			'VoucherNumber'        => $this->VoucherNumber,
			'VoucherSeries'        => $this->VoucherSeries,
			'IsDeleted'            => $this->IsDeleted,
			'State'                => $this->State,
			'ErrorReason'          => $this->ErrorReason,
			'IsBookkept'           => $this->IsBookkept,
			'VoucherSyncReference' => $this->VoucherSyncReference,
			'VoucherSyncTime'      => $this->VoucherSyncTime,
			'CashierSerialNumber'  => $this->CashierSerialNumber,
			'VoucherDate'          => $this->VoucherDate,
			'VoucherText'          => $this->VoucherText,
			'Project'              => $this->Project,
			'CostCenter'           => $this->CostCenter,
			'ReferenceNumber'      => $this->ReferenceNumber,
			'ReferenceType'        => $this->ReferenceType,
			'Rows'                 => $this->Rows,
			'CreatedTime'          => $this->CreatedTime,
			'ModifiedTime'         => $this->ModifiedTime,
		);
	}
}
