<?php

namespace App\Http\Controllers\API;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Http\Response;
use App\Notifications;
use DB;
use Illuminate\Support\Facades\Log;

class NotificationController extends Controller
{


	public function index($id){
		
		try {
			$all = Notifications::where('user_id', $id)->get();
			 if($all){
	            return response()->json(['message' => 'Review request send successfully.', 'data'=> $all], Response::HTTP_OK );     
	        }else{
	            return response()->json(['message' => 'something went wrong!'], Response::HTTP_OK );     
	        }			
		} catch (Exception $e) {
			return response()->json(['message'=>$e->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);    
		}
	}
    public function makeReview($id){
        Log::info('Make Review ');
        Log::debug($id);
        try {
            $data = DB::table('bankuser')
                        ->join('decoration_form','bankuser.bankUserId', '=', 'decoration_form.bankUserId')
                        ->select('decoration_form.associateId','decoration_form.userType','bankuser.bankUserId')
                        ->where('bankuser.bankUserId',$id)->first();
            if($data){
                $notifications = new Notifications();
                $notifications->user_id = $data->associateId;
                $notifications->type = $data->userType;
                $notifications->bank_user_id = $data->bankUserId;
                $notifications->noti_type = 1;
                $res = $notifications->save();
                if($res){
                    return response()->json(['message' => 'Review request send successfully.', 'data'=> true], Response::HTTP_OK );     
                }else{
                    return response()->json(['message' => 'something went wrong!', 'data'=> false], Response::HTTP_OK );     
                }
            }else{
                return response()->json(['message' => 'Data Not Found'], Response::HTTP_OK ); 
            }    
        } catch (Exception $e) {
            return response()->json(['message'=>$e->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);    
        }
    }
}
