<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\users;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\View\Middleware\ShareErrorsFromSessio;

class clienteController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('cliente.cliente');
    }
    public function profile()
    {
        $aplicaciones_cliente =DB::table('usuarios_app')
            ->join('aplicacion','aplicacion.id','usuarios_app.app_id')
            ->where('user_id',Auth::user()->id)
            ->select('usuarios_app.*','aplicacion.nombre as app_name')
            ->get();
        
        $requerimientos_cliente = DB::table('requerimientos')
            ->where('creador',Auth::user()->id)
            ->get();
        return view('cliente.profileCliente',[
            'apps_cliente' => $aplicaciones_cliente,
            'requerimientos_cliente' => $requerimientos_cliente
        ]);
    }
    
    public function requerimientos()
    {
        return view('cliente.requerimientos');
    }
    /**
     * 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($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)
    {
        return redirect('profileCliente');
    }
    public function updateClientePassword(Request $request, $id) {
        $request->validate([
            'newPassword' => 'required|max:20|min:7',
        ]);
        $user = users::find($id);
        $user->password = Hash::make($request->newPassword);
        $user->update();
        return redirect('profileCliente');
    }

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