<?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;
use TourOperatorProFrontend\app\Html\HtmlFrontend;
defined('_TOUROPERATOR_EXEC') or die;
class WishlistController extends ControllerFrontend {
    function change_wishlist(){
        $modelWishlist = Model::getInstance('wishlist');
        $input = Factory::getInput();
        $tour_id = $input->getInt('tour_id',0);
        $user_id=  $input->getInt('user_id',0);
        $db=Factory::getDBO();
        $query = $db->getQuery(true);
        $query->clear()
            ->select('wishlist.*')
            ->from(Utility::getTableName('wishlist') . ' AS wishlist')
            ->where('wishlist.tour_id='.(int)$tour_id)
            ->where('wishlist.user_id='.(int)$user_id);
        $list =  $db->setQuery($query)->loadObjectList();
        if(count($list)>0){
            $query = $db->getQuery(true);
            $query->clear()
                ->delete(Utility::getTableName('wishlist'))
                ->where('tour_id='.(int)$tour_id)
                ->where('user_id='.(int)$user_id);
               
                $db->setQuery($query)->execute();
    
        }else{
            $query = $db->getQuery(true);
            $query->clear()
            ->insert(Utility::getTableName('wishlist'))
            ->set('tour_id='.(int)$tour_id)
            ->set('user_id='.(int)$user_id);
    
            $db->setQuery($query)->execute();
    
           
        }
        return [];
       }
}