<?php

namespace App\Http\Controllers;

use App\Models\Infrastructure;
use App\Models\ManifestationInteret;
use App\Models\TypeUnite;
use Illuminate\Http\Request;
use RealRashid\SweetAlert\Facades\Alert;

class ManifestationInteretClientController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $Infra = Infrastructure::all();
        $TypeUnite = TypeUnite::all();
        return view('Impact.index',compact('Infra','TypeUnite'));
    }

    /**
     * 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)
    {
        $ManifestationInterets = new ManifestationInteret();

        try {
            $ManifestationInterets->nom = $request->input('nom');
            $ManifestationInterets->prenoms = $request->input('prenoms');
            $ManifestationInterets->email = $request->input('email');
            $ManifestationInterets->telephone = $request->input('telephone');
            $ManifestationInterets->infra_id = $request->input('infra_id');
            $ManifestationInterets->typeUnite_id = $request->input('typeUnite_id');
            $ManifestationInterets->nbChambre = $request->input('nbChambre');
            $ManifestationInterets->nbDouche = $request->input('nbDouche');
            $ManifestationInterets->numDossier = $request->input('numDossier');
            $ManifestationInterets->save();
            Alert::success('Message', 'Ajouté avec succès');
            return redirect()->route('ManifestationInteretClient.index');
        } catch (\Illuminate\Database\QueryException $exception) {
            Alert::toast('Veuillez rempli tous champs', 'error');

            return redirect()->back()->withInput();
        }
    }

    /**
     * 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(Request $request, $id)
    {
        //
    }

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