<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DB;
use App\Models\restaurants;

class FindRestaurantController extends Controller
{
    
    public function FindRestaurant_name(Request $request){
        $restaurant_name=$request->restaurant_name;

     $restaurants_id= DB::table('restaurants')->where('name',$restaurant_name)->pluck('id');
        if(count($restaurants_id)>0){
            
            $result =  restaurants::join('dishes', 'dishes.restaurant_id', '=', 'restaurants.id')
            ->select('dishes.name as D_name','dishes.description as D_description','dishes.image as D_image','dishes.price as D_price',
            'dishes.discount_price as D_discount_price','dishes.is_veg as D_is_veg','dishes.glu_free as D_glu_free',
            'dishes.calories as D_calories','dishes.protien as D_protien','dishes.sodium as D_sodium',
            'dishes.addons_category_id as D_addons_category_id','dishes.dish_category_id as D_dish_category_id','dishes.cholesterol as D_cholesterol',
            'restaurants.*')
             ->where('restaurants.name', $restaurant_name)
            
             ->get();
     
         
         return $result ;
        }
    else{
        $msg = "No Restaurants Find";
            return  $msg;
    }

        
    

    }

    public function FindRestaurant_location(Request $request){
        $restaurant_city=$request->restaurant_city;
      //  $restaurant_area=$request->restaurant_area;
      $res_city =   DB::table('restaurant_addresses')->where('address',$restaurant_city)->get();
      if(count($res_city)>0){
        return $res_city;
    }
else{
    $msg = "No Restaurants Find";
        return  $msg;
}
    }

    
    public function FindRestaurant_cuisine(Request $request){
        $cuisine_name=$request->cuisine_name;
        $res_cui_id =   DB::table('foodtypes')->where('name',$cuisine_name)->pluck('id');
            if(count($res_cui_id)>0){
                $get_res_name =   DB::table('restaurants')->where('foodtype_id',$res_cui_id)->get();
                return $get_res_name;
            }
            else{
                $msg = "No Restaurants Find";
                return  $msg;
            }
        }
}
