<?php

namespace App\Http\Controllers;

use App\Models\Immobili;
use Illuminate\Http\Request;

class ImmobiliController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        //
        return view('affitti.immobili.index',[
            'immobili' => Immobili::all()
        ]);
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
        return view('affitti.immobili.create');
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        //
        $data = $request->validate([
            'indirizzo' => 'nullable|string|max:255',
            'citta' => 'nullable|string|max:255',
            'cap' => 'nullable|string|max:20',
            'provincia' => 'nullable|string|max:255',
            'nazione' => 'nullable|string|max:255',
            'descrizione' => 'nullable|string|max:1000',
            'categoria' => 'nullable|string|max:255',
            'tipologia' => 'nullable|string|max:255',
            'stato' => 'nullable|string|max:255',
            'classe_energetica' => 'nullable|string|max:50',
            'superficie' => 'nullable|string|max:50',
            'vani' => 'nullable|string|max:50',
            'bagni' => 'nullable|string|max:50',
            'camere' => 'nullable|string|max:50',
            'piano' => 'nullable|string|max:50',
            'ascensore' => 'nullable|string|max:50',
            'riscaldamento' => 'nullable|string|max:50',
            'condizionatore' => 'nullable|string|max:50',
            'giardino' => 'nullable|string|max:50',
            'posto_auto' => 'nullable|string|max:50',
            'garage' => 'nullable|string|max:50',
            'balcone' => 'nullable|string|max:50',
            'terrazzo' => 'nullable|string|max:50',
            'cantina' => 'nullable|string|max:50',
            'arredamento' => 'nullable|string|max:50',
            'spese_condominiali' => 'nullable|string|max:100',
            'anno_costruzione' => 'nullable|string|max:4',
            'prezzo' => 'nullable|string|max:100',
            'disponibilita' => 'nullable|string|max:255',
            'note' => 'nullable|string|max:2000',
            'fibra-ottica' => 'nullable|string|max:50',
            'internet' => 'nullable|string|max:50',
        ]);
        Immobili::create($data);
        return redirect()->route('immobili')->with('success', 'Immobile creato con successo.');
    }

    /**
     * Display the specified resource.
     */
    public function show(Immobili $immobili)
    {
        //
        $immobile=Immobili::find($immobili->id);
        return view('affitti.immobili.show',compact('immobile'));
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(Immobili $immobili)
    {
        //

    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, Immobili $immobili)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(Immobili $immobili)
    {
        //
        $immobile=Immobili::find($immobili->id);
        $immobile->delete();
        return redirect()->route('immobili')->with('success', 'Immobile eliminato con   successo.');
    }

    public function associaContratto(Immobili $immobili)
    {
        $immobile=Immobili::find($immobili);
        return view('affitti.immobili.assegna-contratto',[compact('immobile'),'id'=>$immobili]);
    }
}
