<?php
defined('_WPBOOKINGPRO_EXEC') or die;
use Woobooking\CMS\Registry\Registry;
if(!class_exists("WpBookingPro_PaymentModel")) {
    /**
     * Class WpBookingPro_PaymentModel
     */
    class WpBookingPro_PaymentModel extends WoobookingModelForm
    {
        /**
         * @var string
         */
        public $context = "payment";
        /**
         * @var string
         */
        public $table_name = "payment";

        /**
         * @param int $id
         * @return mixed|object
         */
        public function getItem($id = 0)
        {
            $item = (object)parent::getItem($id);
            $register = new Registry();
            $register->loadString($item->params);
            $item->params = $register;
            return $item;
        }

        /**
         * @param $payment_id
         * @return mixed
         */
        public function getPaymentPlugin($payment_id)
        {
            $payment = $this->getItem($payment_id);
            $paymentPlugin = WBPayment::getInstance($payment->type, $payment);
            return $paymentPlugin;
        }
    }
}
