<?php
namespace PortalPeople\OrderWebhook\Block\Adminhtml\Order;

use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Registry;

class NgaugeFields extends Template
{
    protected $coreRegistry;

    public function __construct(
        Context $context,
        Registry $registry,
        array $data = []
    ) {
        $this->coreRegistry = $registry;
        parent::__construct($context, $data);
    }

    public function getOrder()
    {
        return $this->coreRegistry->registry('current_order');
    }

    public function getNgaugeOrderNo(): ?string
    {
        $order = $this->getOrder();
        return $order ? $order->getData('ngauge_order_no') : null;
    }

    public function getNgaugeOrderId(): ?string
    {
        $order = $this->getOrder();
        return $order ? $order->getData('ngauge_order_id') : null;
    }

    public function getNgaugeOrderLink(): ?string
    {
        $order = $this->getOrder();
        return $order ? $order->getData('ngauge_order_link') : null;
    }

    public function hasNgaugeData(): bool
    {
        return (bool)($this->getNgaugeOrderNo() || $this->getNgaugeOrderId());
    }

    public function getResendUrl(): string
    {
        $order = $this->getOrder();
        if (!$order) {
            return '';
        }
        return $this->getUrl(
            'portalpeople_orderwebhook/order/resendwebhook',
            ['order_id' => $order->getId()]
        );
    }
}
