<?php

namespace App\Http\Controllers;

use App\Models\TipoBiene;
use App\Http\Requests\TipoBieneRequest;

/**
 * Class TipoBieneController
 * @package App\Http\Controllers
 */
class TipoBieneController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $tipoBienes = TipoBiene::paginate();

        return view('tipo-biene.index', compact('tipoBienes'))
            ->with('i', (request()->input('page', 1) - 1) * $tipoBienes->perPage());
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        $tipoBiene = new TipoBiene();
        return view('tipo-biene.create', compact('tipoBiene'));
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(TipoBieneRequest $request)
    {
        TipoBiene::create($request->validated());

        return redirect()->route('tipo-bienes.index')
            ->with('success', 'TipoBiene created successfully.');
    }

    /**
     * Display the specified resource.
     */
    public function show($id)
    {
        $tipoBiene = TipoBiene::find($id);

        return view('tipo-biene.show', compact('tipoBiene'));
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit($id)
    {
        $tipoBiene = TipoBiene::find($id);

        return view('tipo-biene.edit', compact('tipoBiene'));
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(TipoBieneRequest $request, TipoBiene $tipoBiene)
    {
        $tipoBiene->update($request->validated());

        return redirect()->route('tipo-bienes.index')
            ->with('success', 'TipoBiene updated successfully');
    }

    public function destroy($id)
    {
        TipoBiene::find($id)->delete();

        return redirect()->route('tipo-bienes.index')
            ->with('success', 'TipoBiene deleted successfully');
    }
}
