<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Metier\GestNotes;
use App\Metier\GestSession;
use App\Models\Session;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Response as HttpResponse;

class NoteController extends Controller
{
    protected $gestNotes;
    public function __construct(GestNotes $gestNotes,GestSession $gestSession){
       $this->gestNotes = $gestNotes ;
       $this->gestSession=$gestSession;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
         //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        if (!$request->has([
           'id_Etudiant',
           'id_Station',
           'inputs'])
        ){
            return response()->json(['error' => 'Bad request'], HttpResponse::HTTP_BAD_REQUEST);
        }else {
             $this->gestNotes->attributeNote($request->input('id_Station'),
                $request->input('id_Etudiant'),$request->input('inputs'));
             return $this->gestSession->getSessions();
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update($id_Session,$id_Examen)
    {
        $this->gestNotes->calculeNoteExamen($id_Examen);
            return redirect('/session/'.$id_Session.'/examen');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
