<?php

namespace Sibs\Stargate\Webhooks;

defined('ABSPATH') || exit;

class SibsWebhookData implements \JsonSerializable
{
    /**
     * @var bool
     */
    private $isTest;

    /**
     * @var array
     */
    private $content;

    /**
     * Constructor.
     */
    public function __construct(string $content = '')
    {
        if (0 === strpos($content, 'WebhookTest')) {
            $this->isTest = true;
            $this->content = [];
        } else {
            $this->isTest = false;
            $this->content = json_decode($content, true) ?? [];
        }
    }

    public function isTest(): bool
    {
        return $this->isTest;
    }

    public function getContent(): array
    {
        return $this->content;
    }

    public function hasNotificationId(): bool
    {
        return array_key_exists('notificationID', $this->content);
    }

    public function getNotificationId(): string
    {
        return $this->hasNotificationId() ? $this->content['notificationID'] : '';
    }

    public function jsonSerialize(): array
    {
        return $this->content;
    }
}
