<?php

use AuthStack\Driver\AUDGeneric\App\Controllers\AUDImport;
use AuthStack\Driver\AUDGeneric\App\Controllers\AUDPassword;

$driver = DB::table('drivers')->where('title', 'AUD Generic Driver')
    ->first();

if (!empty($driver)) {
    Route::middleware(['aud'])->controller(AUDImport::class)->group(function () {
        Route::prefix('aud')->group(function () {
            // Create AUD accounts
            Route::post('import', 'import')
                ->name('aud.import');
        });
    });

    Route::middleware(['web'])->controller(AUDPassword::class)->group(function () {
        Route::prefix('aud')->group(function () {
            // Reset password routes
            Route::get('password/reset/{token}', 'passwordResetWithToken')
                ->name('aud.password.token');
        });
    });

    Route::prefix('aud')->controller(AUDPassword::class)->group(function () {
        // Reset password routes
        Route::get('forgot-password', 'passwordInit')
            ->name('aud.password.init');

        Route::post('forgot-password', 'passwordReset')
            ->name('aud.password.forgot');

        Route::post('password/update', 'updatePassword')
            ->name('aud.password.update');

        Route::post('sp/password/reset', 'passwordResetFromSP')
            ->name('aud.sp.password.reset');
    });
}