<?php

namespace App\Http\Controllers;

use App\Models\Engineer;
use App\Models\PendingEngineer;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;

class ApproveEngineerController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create(Request $request)
    {
        // $engineer = App\Http\Controllers\PendingEngineer::where('id', $request->id)->firstOrFail();
        // return Jetstream::inertia()->render($request, 'Auth/Confirm/Engineer', ['engineer' => $engineer]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param Request $request
     * @return Response
     */
    public function store(Request $request)
    {
        $pendingEngineer = Engineer::where('id', $request->id)->firstOrFail();

        $pendingEngineer->user()->update([
            'password' => bcrypt($request->password),
        ]);

        $user = $pendingEngineer->user;
        
        $user->sendEmailVerificationNotification();

        Auth::login($user);

        return Redirect::route('engineer.dashboard');
    }

    /**
     * Update the specified resource in storage.
     *
     * @param Request $request
     * @param int $id
     * @return Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param int $id
     * @return Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param int $id
     * @return Response
     */
    public function edit($id)
    {
        //
    }

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