<?php

namespace TourOperatorProFrontend\app\controllers;

use TourOperatorPro\Factory;
use TourOperatorPro\Filesystem\Support\StringController;
use TourOperatorPro\Mvc\Controller\ControllerFrontend;
use TourOperatorPro\Mvc\Model\Model;
use TourOperatorPro\Utilities\Utility;
use TourOperatorProFrontend\app\helpers\ConfigHelper;
use TourOperatorProFrontend\app\helpers\EmailHelper;

defined('_TOUROPERATOR_EXEC') or die;

/**
 * Class BlockController
 */
class CheckoutController extends ControllerFrontend
{
    public function booknow()
    {
        $root_url = Factory::getUri()->toString();
        $input = Factory::getInput();
        $appConfig = Factory::getAppConfig();
        $data = $input->getData();
        $is_enable_send_sms = $appConfig->get('is_enable_send_sms','');
        $modelCheckout = Model::getInstance('checkout');
        $order = $modelCheckout->checkout_model($data);
        if ($is_enable_send_sms ==1){
            $modelCheckout->send_sms_after_booking($order->id);
        }
        $headers = array(
            'Content-Type: text/html; charset=UTF-8',
            'From: Tour operator admin'
        );
        header("Location: $root_url/?view=checkout-thanks&order_id=" . $order->id);
        die;
    }

    public function check_coupon()
    {
        $input = Factory::getInput();
        $code = $input->getString('code', "");
        $tour_id = $input->getString('tour_id', 0);
        $couponModel = Model::getInstance('coupon');
        $coupon = $couponModel->getItemByCode($code);
        return $coupon;

    }
}
