<?php

namespace Sibs\Stargate\Dto;

class MerchantDto extends AbstractDto
{
    /** @var string */
    public $transactionId;

    /** @var int */
    public $terminalId;

    /** @var string */
    public $merchantName;

    /** @var bool */
    public $inApp;

    /**
     * Constructor.
     */
    public function __construct(
        string $transactionId,
        int $terminalId,
        string $merchantName,
        bool $inApp
    ) {
        $this->transactionId = $transactionId;
        $this->terminalId = $terminalId;
        $this->merchantName = $merchantName;
        $this->inApp = $inApp;
    }

    /**
     * From Array.
     */
    public static function fromArray(array $data): self
    {
        return new self(
            $data['transactonId'] ?? $data['transactionId'] ?? $data['transactionID'] ?? '',
            (int) ($data['terminalId'] ?? $data['terminalID'] ?? 0),
            $data['merchantName'] ?? '',
            filter_var($data['inApp'] ?? false, FILTER_VALIDATE_BOOLEAN)
        );
    }
}
