<?php

use App\Http\Controllers\AssesmentFormController;
use App\Http\Controllers\AssessmentHistoryController;
use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\Auth\PasswordResetLinkController;
use App\Http\Controllers\Auth\ProfileController;
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\Auth\TwoStepVerifyController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\LocationController;
use App\Http\Controllers\MasterData\IndicatorController;
use App\Http\Controllers\MasterData\LandController;
use App\Http\Controllers\MasterData\RuleController;
use App\Http\Controllers\MasterData\UserController;
use Illuminate\Routing\RouteGroup;
use Illuminate\Routing\RouteUrlGenerator;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::middleware('guest')->group(function () {

    Route::name('auth.')->group(function () {

        Route::controller(AuthenticatedSessionController::class)->group(function () {
            Route::get('/', 'create')->name('login');
            Route::post('/', 'store')->name('login_post');
        });

        Route::controller(RegisteredUserController::class)->group(function () {
            Route::get('/registrasi', 'create')->name('register');
            Route::post('/registrasi', 'store')->name('register_post');
        });

        Route::controller(TwoStepVerifyController::class)->group(function () {
            Route::get('/verifikasi-akun/{email}', 'create')->name('two_step_verify');
            Route::post('/verifikasi-akun', 'store')->name('two_step_verify_post');
            Route::post('/verifikasi-akun/resend', 'resendEmail')->name('two_step_verify_resend');
        });

        Route::controller(PasswordResetLinkController::class)->group(function () {
            Route::get('/forgot-password', 'create')->name('forgot_password');
            Route::post('/reset-password', 'store')->name('reset_password');

            Route::get('/validasi-lupa-password/{token}', 'createNewPasswordForm')->name('create_new_password_form');
            Route::post('/validasi-lupa-password', 'storeNewPasswordForm')->name('store_new_password_form');
        });
    });
});

Route::middleware(['auth', 'verifiedAcount'])->group(function () {
    Route::post('/logout', [AuthenticatedSessionController::class, 'destroy'])->name('auth.logout');

    Route::prefix('profile')->controller(ProfileController::class)->name('profile.')->group(function () {
        Route::get('/', 'index')->name('index');
        Route::put('/', 'updateData')->name('update_data');
        Route::put('/password', 'updatePassword')->name('update_password');
    });

    Route::prefix('location')->controller(LocationController::class)->name('location.')->group(function () {
        Route::get('/get-province', 'getProvinces')->name('get_provinces');
        Route::get('/get-regency/{id}', 'getRegencies')->name('get_regencies');
        Route::get('/get-district/{id}', 'getDistricts')->name('get_districts');
    });

    Route::middleware('admin')->group(function () {
        Route::get('/dashboard-admin', [DashboardController::class, 'admin'])->name('dashboard.admin');

        Route::name('master_data.')->group(function () {

            Route::prefix('data-pengguna')->controller(UserController::class)->name('pengguna.')->group(function () {
                Route::get('/', 'index')->name('index');
                Route::post('/', 'store')->name('store');
                Route::put('/{id}', 'update')->name('update');
                Route::delete('/{id}', 'destroy')->name('destroy');
            });

            Route::prefix('data-lahan')->controller(LandController::class)->name('lahan.')->group(function () {
                Route::get('/', 'index')->name('index');
                Route::get('/tambah', 'create')->name('create');
                Route::post('/', 'store')->name('store');
                Route::get('/edit/{id}', 'edit')->name('edit');
                Route::put('/edit/{id}', 'update')->name('update');
                Route::delete('/{id}', 'destroy')->name('destroy');
            });

            Route::prefix('data-indikator')->controller(IndicatorController::class)->name('indikator.')->group(function () {
                Route::get('/', 'index')->name('index');
                Route::post('/', 'store')->name('store');
                Route::put('/{id}', 'update')->name('update');
                Route::delete('/{id}', 'destroy')->name('destroy');
            });

            Route::prefix('data-aturan')->controller(RuleController::class)->name('aturan.')->group(function () {
                Route::get('/', 'index')->name('index');
                Route::post('/', 'store')->name('store');
                Route::put('/{id}', 'update')->name('update');
                Route::delete('/{id}', 'destroy')->name('destroy');
            });
        });

        Route::prefix('riwayat-penilaian')->controller(AssessmentHistoryController::class)->name('assessment_history.')->group(function () {
            Route::get('/', 'index')->name('index');
        });
    });

    Route::middleware('officer')->group(function () {
        Route::get('/dashboard-petugas', [DashboardController::class, 'petugas'])->name('dashboard.petugas');

        Route::prefix('form-penilaian')->controller(AssesmentFormController::class)->name('assesment_form.')->group(function () {
            Route::get('/', 'index')->name('index');
            Route::post('/', 'store')->name('store');
        });

        Route::prefix('riwayat-penilaian-lahan')->controller(AssessmentHistoryController::class)->name('assessment_history_officer.')->group(function () {
            Route::get('/', 'officer')->name('index');
        });

        Route::prefix('data-lahan-petugas')->controller(LandController::class)->name('lahan.')->group(function () {
            Route::get('/', 'index')->name('index');
            Route::get('/tambah', 'create')->name('create');
            Route::post('/tambah', 'store')->name('store');
            Route::get('/edit/{id}', 'edit')->name('edit');
            Route::put('/edit/{id}', 'update')->name('update');
            Route::delete('/{id}', 'destroy')->name('destroy');
        });
    });
});
