<?php

namespace App\Http\Controllers\Auth;

//Library
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
use Throwable;

//Models
use App\Models\Auth\User;
use App\Models\Esi\EsiScope;

class EsiScopeController extends Controller
{
    /**
     * Class Construction
     * 
     * @return null
     */
    public function __construct() {
        $this->middleware('auth');
        $this->middleware('role:User');
    }

    /**
     * Display the ESI scopes to choose from
     * 
     * @return view
     */
    public function displayScopes() {
        $scopes = EsiScope::where([
            'character_id' => Auth::user()->character_id,
        ])->get();

        return view('scopes.select')->with('scopes', $scopes);
    }

    /**
     * Redirect to the socialite provider
     * 
     * @return RequestResponse
     */
    public function redirectToProvider(Request $request): RequestResponse
    {
        return Socialite::driver('eveonline')->setScopes($request->scopes)->redirect();
    }
}
