<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Encadrant_Stage_Etudiant;
use App\Models\Etudiant;
use App\Metier\GestStage;
use Illuminate\Http\Response as HttpResponse;

class StageStudentController extends Controller
{
    protected $gestStage;
    public function __construct(GestStage $gestStage){
       $this->gestStage = $gestStage;
    }
    /**
     * 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)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($encadrantId = null,$stageId = null,$studentId = null)
    {
        //afficher all student of specifique encadrant of specifique stage of a specifique encadrant
        if(is_null($studentId)){
            return  Encadrant_Stage_Etudiant::join('Etudiant', 'Etudiant.id_Etudiant', '=',
                'Encadrant_Stage_Etudiant.id_Etudiant')->select('Etudiant.*')
                ->where('Encadrant_Stage_Etudiant.id_Enseignant','=',$encadrantId)
                ->where('Encadrant_Stage_Etudiant.id_Stage','=',$stageId)
                ->distinct()->get();
        } else {
            $etudiant=Etudiant::find($studentId );
            return is_null($etudiant) ?  response()->
            json(['error' => 'etudiant Note not found'], HttpResponse::HTTP_NOT_FOUND) : $etudiant;
        }
    }

    /**
     * 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(Request $request,$encadrantId = null,$stageId = null,$studentId = null)
    {
        $this->gestStage->validateStage($encadrantId, $studentId, $stageId);
    }

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