<?php

namespace WpBookingHotelFrontend\app\controllers;

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

defined('_WPBOOKINGHOTEL_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','');
        $is_enable_add_google_calendar_api = $appConfig->get('is_enable_add_google_calendar_api','');
        $client_secret_file = $appConfig->get('client_secret_file','');
        $modelCheckout = Model::getInstance('checkout');
        $order = $modelCheckout->checkout_model($data);
        /*if ($is_enable_send_sms ==1){
            $modelCheckout->send_sms_after_booking($order->id);
        }*/
        if ($is_enable_add_google_calendar_api == 1){
            if($client_secret_file !== '' && file_exists(WPBOOKINGHOTEL_PATH_ROOT.DS.$client_secret_file)) {
                $modelCheckout->add_google_calendar($order->id);
            }
        }
        header("Location: $root_url/?view=checkout-thanks&order_id=" . $order->id);
        die;
    }

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



}
