<?php

namespace Sibs\Sibs\Model\Config\Source;

use Magento\Config\Model\Config\CommentInterface;
use Magento\Framework\UrlInterface;
use Sibs\Sibs\DB\SibsDB;

class WebhookComment implements CommentInterface
{
    protected $urlInterface;

    public function __construct(
        UrlInterface $urlInterface
    ) {
        $this->urlInterface = $urlInterface;
    }

    public function getCommentText($elementValue)
    {
        $webhookURL = self::getWebhookURL();

        $commentValue = __("Place here your SIBS' Webhook Secret.");
        $commentValue .= '<p><b>' . __('Webhook Endpoint') . ': </b>' .
            '<a href="' . $webhookURL . '">' . $webhookURL . '</a>' .
        '</p>';

        return $commentValue;
    }

    private static function getWebhookURL()
    {
        $storeManager    = SibsDB::get('\Magento\Store\Model\StoreManagerInterface');
        $domain          = $storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_WEB);
        $webhookEndpoint = 'rest/V1/webhook';

        return $domain . $webhookEndpoint;
    }
}
