<?php

namespace Sibs\Stargate\Dto;

class WebhookDto extends AbstractDto
{
    /** @var ReturnStatusDto */
    public $returnStatus;

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

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

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

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

    /** @var AmountDto */
    public $amount;

    /** @var MerchantDto */
    public $merchant;

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

    /** @var TokenDto */
    public $token;

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

    /**
     * Constructor.
     */
    public function __construct(
        ReturnStatusDto $returnStatus,
        string $paymentStatus,
        string $paymentMethod,
        string $transactionId,
        string $transactionDateTime,
        AmountDto $amount,
        MerchantDto $merchant,
        string $paymentType,
        TokenDto $token,
        string $notificationID
    ) {
        $this->returnStatus = $returnStatus;
        $this->paymentStatus = $paymentStatus;
        $this->paymentMethod = $paymentMethod;
        $this->transactionId = $transactionId;
        $this->transactionDateTime = $transactionDateTime;
        $this->amount = $amount;
        $this->merchant = $merchant;
        $this->paymentType = $paymentType;
        $this->token = $token;
        $this->notificationID = $notificationID;
    }

    /**
     * From Array.
     */
    public static function fromArray(array $data): self
    {
        return new self(
            ReturnStatusDto::fromArray($data['returnStatus'] ?? []),
            $data['paymentStatus'] ?? '',
            $data['paymentMethod'] ?? '',
            $data['transactionID'] ?? '',
            $data['transactionDateTime'] ?? '',
            AmountDto::fromArray($data['amount'] ?? []),
            MerchantDto::fromArray($data['merchant'] ?? []),
            $data['paymentType'] ?? '',
            TokenDto::fromArray($data['token'] ?? []),
            $data['notificationID'] ?? ''
        );
    }
}
