<?php

namespace Sibs\Sibs\Model;

use Magento\Payment\Model\Method\AbstractMethod;

abstract class SibsPayment extends AbstractMethod
{
    /**
     * SIBS Payment Method
     * 
     * @var string
     */
    protected $_paymentMethod;

    /**
     * Store Manager
     *
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $_storeManager;

    /**
     * @param \Magento\Framework\Model\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
     * @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
     * @param \Magento\Payment\Helper\Data $paymentData
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
     * @param \Magento\Payment\Model\Method\Logger $logger
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
     * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
     * @param array $data
     * @param \Magento\Directory\Helper\Data $directory
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
     */
    public function __construct(
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
        \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
        \Magento\Payment\Helper\Data $paymentData,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Payment\Model\Method\Logger $logger,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        array $data = [],
        \Magento\Directory\Helper\Data $directory = null
    ) {
        $this->_storeManager = $storeManager;

        parent::__construct(
            $context,
            $registry,
            $extensionFactory,
            $customAttributeFactory,
            $paymentData,
            $scopeConfig,
            $logger,
            $resource,
            $resourceCollection,
            $data,
            $directory
        );
    }

    /**
     * Get Payment Email HTML
     *
     * @param SibsOrder $sibsOrder
     * @return string
     */
    abstract public function getPaymentEmailHTML(SibsOrder $sibsOrder): string;

    /**
     * Get SIBS Payment Method.
     *
     * @return string
     */
    public function getPaymentMethod(): string
    {
        return $this->_paymentMethod;
    }

    /**
     * Get Store View Currency Code
     *
     * @param string $currencyCode
     * @return string
     */
    public function getStoreViewCurrencyCode($currencyCode)
    {
        return $this->_storeManager->getStore()->getCurrentCurrency()->getCode() ?? $currencyCode;
    }

    /**
     * Check order availability
     *
     * @return bool
     * @api
     */
    public function canOrder()
    {
        return $this->getConfigData('canOrder') ?? $this->_canOrder;
    }

    /**
     * Check authorize availability
     *
     * @return bool
     * @api
     */
    public function canAuthorize()
    {
        return $this->getConfigData('canAuthorize') ?? $this->_canAuthorize;
    }

    /**
     * Check capture availability
     *
     * @return bool
     * @api
     */
    public function canCapture()
    {
        return $this->getConfigData('canCapture') ?? $this->_canCapture;
    }

    /**
     * Check partial capture availability
     *
     * @return bool
     * @api
     */
    public function canCapturePartial()
    {
        return $this->getConfigData('canCapturePartial') ?? $this->_canCapturePartial;
    }

    /**
     * Check whether capture can be performed once and no further capture possible
     *
     * @return bool
     * @api
     */
    public function canCaptureOnce()
    {
        return $this->getConfigData('canCaptureOnce') ?? $this->_canCaptureOnce;
    }

    /**
     * Check refund availability
     *
     * @return bool
     * @api
     */
    public function canRefund()
    {
        return $this->getConfigData('canRefund') ?? $this->_canRefund;
    }

    /**
     * Check partial refund availability for invoice
     *
     * @return bool
     * @api
     */
    public function canRefundPartialPerInvoice()
    {
        return $this->getConfigData('canRefundInvoicePartial') ?? $this->_canRefundInvoicePartial;
    }

    /**
     * Check void availability
     * @return bool
     * @internal param \Magento\Framework\DataObject $payment
     * @api
     */
    public function canVoid()
    {
        return $this->getConfigData('canVoid') ?? $this->_canVoid;
    }

    /**
     * Using internal pages for input payment data
     * Can be used in admin
     *
     * @return bool
     */
    public function canUseInternal()
    {
        return $this->getConfigData('canUseInternal') ?? $this->_canUseInternal;
    }

    /**
     * Can be used in regular checkout
     *
     * @return bool
     */
    public function canUseCheckout()
    {
        return $this->getConfigData('canUseCheckout') ?? $this->_canUseCheckout;
    }

    /**
     * Can be edit order (renew order).
     *
     * @return bool
     * @api
     */
    public function canEdit()
    {
        return $this->getConfigData('canEdit') ?? false;
    }

    /**
     * Retrieve payment system relation flag
     *
     * @return bool
     * @api
     */
    public function isGateway()
    {
        return $this->getConfigData('isGateway') ?? $this->_isGateway;
    }

    /**
     * Retrieve payment method online/offline flag
     *
     * @return bool
     * @api
     */
    public function isOffline()
    {
        return $this->getConfigData('isOffline') ?? $this->_isOffline;
    }

    /**
     * Flag if we need to run payment initialize while order place
     *
     * @return bool
     * @api
     */
    public function isInitializeNeeded()
    {
        return $this->getConfigData('isInitializeNeeded') ?? $this->_isInitializeNeeded;
    }

    /**
     * Whether this method can accept or deny payment
     * @return bool
     * @api
     */
    public function canReviewPayment()
    {
        return $this->getConfigData('canReviewPayment') ?? $this->_canReviewPayment;
    }
}
