<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\KampusController;
use App\Http\Controllers\ProdiController;
use App\Http\Controllers\MahasiswaController;
use App\Http\Controllers\PengajuanStatusController;
use App\Http\Controllers\BiayaMasterController;
use App\Http\Controllers\TambahBiayaController;
use App\Http\Controllers\PotonganBiayaController;
use App\Http\Controllers\AngsuranController;
use App\Http\Controllers\MetodePembayaranController;
use App\Http\Controllers\RapController;
use App\Http\Controllers\RapBonusRuleController;
use App\Http\Controllers\ValidasiPengajuanController;
use App\Http\Controllers\ValidasiMahasiswaController;
use App\Http\Controllers\ValidasiRencanaController;
use App\Http\Controllers\ValidasiPembayaranController;
use App\Http\Controllers\ValidasiRapController;
use App\Http\Controllers\ValidasiPotonganController;
use App\Http\Controllers\LaporanRapController;
use App\Http\Controllers\LaporanAlokasiPendaftaranController;
use App\Http\Controllers\LaporanAlokasiHerregistrasiController;
use App\Http\Controllers\LaporanAlokasiAngsuranController;
use App\Http\Controllers\LaporanPerolehanMarketingController;
use App\Http\Controllers\LaporanPerolehanTelemarketingController;
use App\Http\Controllers\LaporanDaftarHerregistrasiController;
use App\Http\Controllers\LaporanKeseluruhanController;
use App\Http\Controllers\LaporanSumberInformasiController;
use App\Http\Controllers\ImportPembayaranAngsuranController;
use App\Http\Controllers\LogAktivitasController;


Route::get('/', function () {
    return view('welcome');
});

/*
|--------------------------------------------------------------------------
| Dashboard
|--------------------------------------------------------------------------
*/
Route::get('/dashboard', [DashboardController::class, 'index'])
    ->middleware(['auth', 'verified'])
    ->name('dashboard');

Route::get('/dashboard/clear-cache', [DashboardController::class, 'clearCache']);

/*
|--------------------------------------------------------------------------
| Profile
|--------------------------------------------------------------------------
*/
Route::middleware('auth')->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN (Manajemen Role)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin'])->group(function () {
    Route::resource('roles', RoleController::class);
    Route::post('/roles/bulk-destroy', [RoleController::class, 'bulkDestroy'])->name('roles.bulk-destroy');
    Route::get('/roles/data/all', [RoleController::class, 'getData'])->name('roles.data');
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN (Manajemen User)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin'])->group(function () {
    Route::resource('users', UserController::class);
    Route::post('/users/bulk-destroy', [UserController::class, 'bulkDestroy'])->name('users.bulk-destroy');
    Route::post('/users/{user}/reset-password', [UserController::class, 'resetPassword'])->name('users.reset-password');
    Route::get('/users/data/all', [UserController::class, 'getData'])->name('users.data');
});

// AJAX Routes untuk semua user yang terautentikasi
Route::middleware(['auth'])->group(function () {
    Route::get('/get-prodi/{kampus}', [MahasiswaController::class, 'getProdi'])
        ->name('get-prodi');

    Route::get('/get-prodi-by-kampus/{kampus_id}', [BiayaMasterController::class, 'getProdiByKampus'])
        ->name('get-prodi-by-kampus');

    Route::get('/validasi-pembayaran/get-prodi/{kampus_id}', [ValidasiPembayaranController::class, 'getProdiByKampus'])
        ->name('validasi.pembayaran.get-prodi');

    Route::get('/prodi/get-jenjang/{kampusId}', [ProdiController::class, 'getJenjangList'])->name('prodi.getJenjang');
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN, RND (Manajemen Kampus, Prodi, Biaya Master)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin,rnd,manager keuangan'])->group(function () {
    // CRUD KAMPUS
    Route::resource('kampus', KampusController::class);
    Route::get('/kampus/{id}/detail', [KampusController::class, 'getDetail'])->name('kampus.detail');

    // CRUD PRODI
    Route::resource('prodi', ProdiController::class);

    // CRUD BIAYA MASTER
    Route::resource('biaya-master', BiayaMasterController::class)->except(['show']);

    // Bulk operations untuk Biaya Master
    Route::post('/biaya-master/save-selection', [BiayaMasterController::class, 'saveSelection'])->name('biaya-master.save-selection');
    Route::post('/biaya-master/clear-selection', [BiayaMasterController::class, 'clearSelection'])->name('biaya-master.clear-selection');
    Route::get('/biaya-master/get-selection', [BiayaMasterController::class, 'getSelection'])->name('biaya-master.get-selection');
    Route::get('/biaya-master/get-all-ids', [BiayaMasterController::class, 'getAllIds'])->name('biaya-master.get-all-ids');
    Route::get('/biaya-master/bulk-edit', [BiayaMasterController::class, 'bulkEdit'])->name('biaya-master.bulk.edit');
    Route::post('/biaya-master/bulk-update', [BiayaMasterController::class, 'bulkUpdate'])->name('biaya-master.bulk.update');
    Route::post('/biaya-master/bulk-destroy', [BiayaMasterController::class, 'bulkDestroy'])->name('biaya-master.bulk.destroy');
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN, MARKETING, MANAGER PENAGIHAN, PENAGIHAN, RND (Tambah Biaya)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin,manager penagihan,penagihan,rnd'])->group(function () {
    // BULK INJECT BIAYA
    Route::get('/tambah-biaya', [TambahBiayaController::class, 'index'])->name('tambah-biaya.index');
    Route::post('/tambah-biaya/inject', [TambahBiayaController::class, 'inject'])->name('tambah-biaya.inject');
    Route::get('/tambah-biaya/detail/{id}', [TambahBiayaController::class, 'getDetail'])->name('tambah-biaya.detail');
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN, MARKETING, MANAGER PENAGIHAN, PENAGIHAN (Potongan Biaya)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin,manager keuangan,keuangan'])->group(function () {
    // POTONGAN BIAYA
    Route::get('/potongan-biaya', [PotonganBiayaController::class, 'index'])->name('potongan-biaya.index');
    Route::post('/potongan-biaya/apply', [PotonganBiayaController::class, 'applyPotongan'])->name('potongan-biaya.apply');
    Route::post('/potongan-biaya/available-jenis', [PotonganBiayaController::class, 'getAvailableJenis'])->name('potongan-biaya.available-jenis');
    Route::post('/potongan-biaya/summary-potongan', [PotonganBiayaController::class, 'getSummaryPotongan'])->name('potongan-biaya.summary-potongan');
    Route::get('/potongan-biaya/detail/{id}', [PotonganBiayaController::class, 'getDetail'])->name('potongan-biaya.detail');
    Route::post('/potongan-biaya/summary', [PotonganBiayaController::class, 'getSummary'])->name('potongan-biaya.summary');
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN (Metode Pembayaran)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin'])->group(function () {
    // METODE PEMBAYARAN
    Route::resource('metode-pembayaran', MetodePembayaranController::class);
    Route::post('/metode-pembayaran/{id}/toggle', [MetodePembayaranController::class, 'toggleStatus'])->name('metode-pembayaran.toggle');
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN, MARKETING, TELEMARKETING (Mahasiswa)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin,marketing,telemarketing'])->group(function () {
    // CRUD MAHASISWA
    Route::resource('mahasiswa', MahasiswaController::class);

    // Cari Marketing Kampus
    Route::get('/get-marketing-by-kampus/{kampusId}', [MahasiswaController::class, 'getMarketingByKampus'])->name('get-marketing-by-kampus');
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN, MARKETING, MANAGER PENAGIHAN, PENAGIHAN (Angsuran)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin,marketing,manager penagihan,penagihan'])->group(function () {
    Route::get('/angsuran/generate/{mahasiswa_id}', [AngsuranController::class, 'generate'])->name('angsuran.generate');
    Route::get('/angsuran/{id}', [AngsuranController::class, 'show'])->name('angsuran.show');
    Route::post('/angsuran/bayar/{id}', [AngsuranController::class, 'bayar'])->name('angsuran.bayar');
    Route::post('/angsuran/bulk-bayar/{id}', [AngsuranController::class, 'bulkBayar'])->name('angsuran.bulk.bayar');
    Route::post('/angsuran/bayar-lunas/{detail_id}', [AngsuranController::class, 'bayarLunas'])->name('angsuran.bayar.lunas');
    Route::post('/angsuran/bayar-lunas-all/{angsuran_id}', [AngsuranController::class, 'bayarLunasAll'])->name('angsuran.bayar.lunas.all');
    Route::get('/angsuran/{id}/preview', [AngsuranController::class, 'preview'])->name('angsuran.preview');
    Route::get('/angsuran/{id}/print', [AngsuranController::class, 'print'])->name('angsuran.print');
    Route::get('/angsuran/{id}/export-pdf', [AngsuranController::class, 'exportPdf'])->name('angsuran.export.pdf');
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN (Pengajuan Status Akademik)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin'])->group(function () {
    // Pengajuan Status Routes
    Route::prefix('pengajuan-status')->name('pengajuan-status.')->group(function () {
        Route::get('/', [PengajuanStatusController::class, 'index'])->name('index');
        Route::post('/store', [PengajuanStatusController::class, 'store'])->name('store');
        Route::post('/bulk-store', [PengajuanStatusController::class, 'bulkStore'])->name('bulk-store');
        Route::get('/search', [PengajuanStatusController::class, 'searchMahasiswa'])->name('search');
        Route::get('/get-prodi/{kampusId}', [PengajuanStatusController::class, 'getProdiByKampus'])->name('get-prodi');
        Route::get('/{id}/download-pengajuan', [PengajuanStatusController::class, 'downloadPengajuanFile'])->name('download-pengajuan');
        Route::get('/{id}/download-bukti', [PengajuanStatusController::class, 'downloadBuktiBayarFile'])->name('download-bukti');
        Route::get('/{id}', [PengajuanStatusController::class, 'show'])->name('show');
    });
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN, MANAGER PENAGIHAN, PENAGIHAN (Import Pembayaran)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin,manager penagihan,penagihan'])->group(function () {
    // IMPORT PEMBAYARAN ANGSURAN
    Route::get('/import/pembayaran-angsuran', [ImportPembayaranAngsuranController::class, 'index'])->name('import.pembayaran-angsuran');
    Route::post('/import/pembayaran-angsuran/preview', [ImportPembayaranAngsuranController::class, 'preview'])->name('import.pembayaran-angsuran.preview');
    Route::post('/import/pembayaran-angsuran/process', [ImportPembayaranAngsuranController::class, 'process'])->name('import.pembayaran-angsuran.process');
    Route::get('/import/pembayaran-angsuran/template', [ImportPembayaranAngsuranController::class, 'downloadTemplate'])->name('import.pembayaran-angsuran.template');
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN, GENERAL AFFAIRS, MANAGER KEUANGAN (RAP)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin,general affairs,manager keuangan'])->group(function () {
    // RAP Routes
    Route::prefix('rap')->name('rap.')->group(function () {
        // Bonus Rules
        Route::prefix('bonus-rules')->name('bonus.')->group(function () {
            Route::get('/', [RapBonusRuleController::class, 'index'])->name('index');
            Route::post('/', [RapBonusRuleController::class, 'store'])->name('store');
            Route::get('/{id}/edit', [RapBonusRuleController::class, 'edit'])->name('edit');
            Route::put('/{id}', [RapBonusRuleController::class, 'update'])->name('update');
            Route::delete('/{id}', [RapBonusRuleController::class, 'destroy'])->name('destroy');
            Route::post('/{id}/toggle', [RapBonusRuleController::class, 'toggleStatus'])->name('toggle');
        });

        // Data Fee & Data Bonus (General Affairs)
        Route::middleware(['role:superadmin,admin,general affairs'])->group(function () {
            Route::get('/data-fee', [RapController::class, 'dataFee'])->name('data-fee');
            Route::get('/data-bonus', [RapController::class, 'dataBonus'])->name('data-bonus');
            Route::post('/update-status-fee', [RapController::class, 'updateStatusFee'])->name('update-status-fee');
            Route::post('/update-status-bonus', [RapController::class, 'updateStatusBonus'])->name('update-status-bonus');
            Route::post('/ajukan-bonus', [RapController::class, 'ajukanBonus'])->name('ajukan-bonus');
            Route::post('/ajukan-bonus-bulk', [RapController::class, 'ajukanBonusBulk'])->name('ajukan-bonus-bulk');
            Route::get('/histori-bonus', [RapController::class, 'historiBonus'])->name('histori-bonus');
            Route::post('/simpan-catatan-histori-bonus/{bonusId}', [RapController::class, 'simpanCatatanHistoriBonus'])->name('simpan-catatan-histori-bonus');
        });

        // Data Approval (Manager Keuangan)
        Route::middleware(['role:superadmin,admin,manager keuangan'])->group(function () {
            Route::get('/data-approval', [RapController::class, 'dataApproval'])->name('data-approval');
            Route::post('/approve-bulk', [RapController::class, 'approveBulk'])->name('approve-bulk');
            Route::post('/tolak-bulk', [RapController::class, 'tolakBulk'])->name('tolak-bulk');
            Route::post('/cairkan-bonus/{id}', [RapController::class, 'cairkanBonus'])->name('cairkan-bonus');
            Route::post('/ajukan-cair-bulk', [RapController::class, 'ajukanCairBulk'])->name('ajukan-cair-bulk');
            Route::post('/approve-cair/{id}', [RapController::class, 'approveCair'])->name('approve-cair');
            Route::post('/tolak-pengajuan/{id}', [RapController::class, 'tolakPengajuan'])->name('tolak-pengajuan');
            Route::post('/approve-bonus-bulk', [RapController::class, 'approveBonusBulk'])->name('approve-bonus-bulk');
            Route::post('/tolak-bonus-bulk', [RapController::class, 'tolakBonusBulk'])->name('tolak-bonus-bulk');
            Route::post('/approve-bonus/{id}', [RapController::class, 'approveBonus'])->name('approve-bonus');
            Route::post('/tolak-bonus/{id}', [RapController::class, 'tolakBonus'])->name('tolak-bonus');
        });

        // Shared Routes untuk semua role di atas
        Route::get('/get-catatan/{komisiId}', [RapController::class, 'getCatatan'])->name('get-catatan');
        Route::get('/get-catatan-bonus/{bonusId}', [RapController::class, 'getCatatanBonus'])->name('get-catatan-bonus');

        // RAP CRUD
        Route::get('/', [RapController::class, 'index'])->name('index');
        Route::get('/create', [RapController::class, 'create'])->name('create');
        Route::post('/store', [RapController::class, 'store'])->name('store');
        Route::get('/cetak-pdf', [RapController::class, 'cetakPdf'])->name('cetak-pdf');
        Route::post('/cetak-pengajuan-pdf', [RapController::class, 'cetakPengajuanPdf'])->name('cetak-pengajuan-pdf');
        Route::post('/cetak-pengajuan-bonus-pdf', [RapController::class, 'cetakPengajuanBonusPdf'])->name('cetak-pengajuan-bonus-pdf');
        Route::get('/{id}/edit', [RapController::class, 'edit'])->name('edit');
        Route::put('/{id}', [RapController::class, 'update'])->name('update');
        Route::put('/{id}/toggle-status', [RapController::class, 'toggleStatus'])->name('toggle-status');
        Route::delete('/{id}', [RapController::class, 'destroy'])->name('destroy');
        Route::get('/{id}/download/{type}', [RapController::class, 'downloadFile'])->name('download');
        Route::get('/{id}', [RapController::class, 'show'])->name('show');
    });
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN, VALIDATOR, MANAGER WILAYAH, ASISTEN MANAGER WILAYAH, MANAGER KEUANGAN (Validasi)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin,validator,manager wilayah,asisten manager wilayah,manager keuangan,'])->group(function () {

    // VALIDASI MAHASISWA (Validator)
    Route::middleware(['role:superadmin,admin,validator'])->group(function () {
        Route::get('/validasi-mahasiswa', [ValidasiMahasiswaController::class, 'index'])->name('validasi.mahasiswa.index');
        Route::get('/validasi-mahasiswa/{id}/detail', [ValidasiMahasiswaController::class, 'detail'])->name('validasi.mahasiswa.detail');
        Route::post('/validasi-mahasiswa/{id}/setujui', [ValidasiMahasiswaController::class, 'setujui'])->name('validasi.mahasiswa.setujui');
        Route::post('/validasi-mahasiswa/{id}/tolak', [ValidasiMahasiswaController::class, 'tolak'])->name('validasi.mahasiswa.tolak');
        Route::post('/validasi-mahasiswa/bulk-setujui', [ValidasiMahasiswaController::class, 'bulkSetujui'])->name('validasi.mahasiswa.bulk.setujui');
        Route::post('/validasi-mahasiswa/bulk-tolak', [ValidasiMahasiswaController::class, 'bulkTolak'])->name('validasi.mahasiswa.bulk.tolak');
    });

    // VALIDASI PENGAJUAN STATUS (Validator)
    Route::middleware(['role:superadmin,admin,manager keuangan'])->group(function () {
        Route::get('/validasi-pengajuan', [ValidasiPengajuanController::class, 'index'])->name('validasi-pengajuan.index');
        Route::post('/validasi-pengajuan/{id}/approve', [ValidasiPengajuanController::class, 'approve'])->name('validasi-pengajuan.approve');
        Route::post('/validasi-pengajuan/{id}/reject', [ValidasiPengajuanController::class, 'reject'])->name('validasi-pengajuan.reject');
        Route::post('/validasi-pengajuan/bulk-action', [ValidasiPengajuanController::class, 'bulkAction'])->name('validasi-pengajuan.bulk-action');
        Route::get('/validasi-pengajuan/get-prodi/{kampusId}', [ValidasiPengajuanController::class, 'getProdiByKampus'])->name('validasi-pengajuan.get-prodi');
        Route::get('/validasi-pengajuan/{id}', [ValidasiPengajuanController::class, 'show'])->name('validasi-pengajuan.show');
        Route::get('/validasi-pengajuan/{id}/download-pengajuan', [ValidasiPengajuanController::class, 'downloadPengajuanFile'])->name('validasi-pengajuan.download-pengajuan');
        Route::get('/validasi-pengajuan/{id}/download-bukti', [ValidasiPengajuanController::class, 'downloadBuktiBayarFile'])->name('validasi-pengajuan.download-bukti');
    });

    // VALIDASI RENCANA (Validator)
    Route::middleware(['role:superadmin,admin,validator'])->group(function () {
        Route::get('/validasi-rencana', [ValidasiRencanaController::class, 'index'])->name('validasi.rencana.index');
        Route::post('/validasi-rencana/{id}/setujui', [ValidasiRencanaController::class, 'setujui'])->name('validasi.rencana.setujui');
        Route::post('/validasi-rencana/bulk-setujui', [ValidasiRencanaController::class, 'bulkSetujui'])->name('validasi.rencana.bulk.setujui');
        Route::get('/validasi-rencana/{id}/detail', [ValidasiRencanaController::class, 'getDetailModal'])->name('validasi.rencana.detail');
    });

    // VALIDASI PEMBAYARAN (Validator)
    Route::middleware(['role:superadmin,admin,validator'])->group(function () {
        Route::get('/validasi-pembayaran', [ValidasiPembayaranController::class, 'index'])->name('validasi.pembayaran.index');
        Route::post('/validasi-pembayaran/{id}/setujui', [ValidasiPembayaranController::class, 'setujui'])->name('validasi.pembayaran.setujui');
        Route::post('/validasi-pembayaran/{id}/tolak', [ValidasiPembayaranController::class, 'tolak'])->name('validasi.pembayaran.tolak');
        Route::post('/validasi-pembayaran/bulk-setujui', [ValidasiPembayaranController::class, 'bulkSetujui'])->name('validasi.pembayaran.bulk.setujui');
        Route::post('/validasi-pembayaran/bulk-tolak', [ValidasiPembayaranController::class, 'bulkTolak'])->name('validasi.pembayaran.bulk.tolak');
    });

    // VALIDASI RAP (Manager Wilayah, Asisten Manager Wilayah)
    Route::middleware(['role:superadmin,admin,manager wilayah,asisten manager wilayah'])->group(function () {
        Route::prefix('validasi-rap')->name('validasi-rap.')->group(function () {
            Route::get('/', [ValidasiRapController::class, 'index'])->name('index');
            Route::get('/{id}', [ValidasiRapController::class, 'show'])->name('show');
            Route::post('/{id}/validate', [ValidasiRapController::class, 'validate'])->name('validate');
            Route::post('/bulk-validate', [ValidasiRapController::class, 'bulkValidate'])->name('bulk-validate');
            Route::get('/{id}/detail-modal', [ValidasiRapController::class, 'getDetailModal'])->name('detail-modal');
        });
    });

    // VALIDASI POTONGAN BIAYA (Manager Keuangan)
    Route::middleware(['role:superadmin,admin'])->group(function () {
        Route::get('/validasi-potongan', [ValidasiPotonganController::class, 'index'])->name('validasi-potongan.index');
        Route::post('/validasi-potongan/setujui-item/{detailId}', [ValidasiPotonganController::class, 'setujuiItem'])->name('validasi-potongan.setujui-item');
        Route::post('/validasi-potongan/tolak-item/{detailId}', [ValidasiPotonganController::class, 'tolakItem'])->name('validasi-potongan.tolak-item');
        Route::post('/validasi-potongan/bulk-setujui', [ValidasiPotonganController::class, 'bulkSetujui'])->name('validasi-potongan.bulk-setujui');
        Route::post('/validasi-potongan/bulk-tolak', [ValidasiPotonganController::class, 'bulkTolak'])->name('validasi-potongan.bulk-tolak');
        Route::get('/validasi-potongan/detail/{id}', [ValidasiPotonganController::class, 'getDetailModal'])->name('validasi-potongan.detail');
    });
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN, MANAGER HRD, HRD, MANAGER WILAYAH, MARKETING, MANAGER TELEMARKETING, TELEMARKETING MANAGER KEUANGAN, KEUANGAN, GENERAL AFFAIRS (Laporan)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth'])->prefix('laporan')->name('laporan.')->group(function () {

    // Laporan RAP - General Affairs
    Route::middleware(['role:superadmin,admin,general affairs'])->group(function () {
        Route::get('/rap', [LaporanRapController::class, 'index'])->name('rap');
        Route::get('/rap/cetak-pdf', [LaporanRapController::class, 'cetakPdf'])->name('rap.cetak-pdf');
    });

    // Laporan Fee Marketing - Manager HRD, HRD, Manager Wilayah, Marketing
    Route::middleware(['role:superadmin,admin,manager hrd,hrd,manager wilayah,marketing'])->group(function () {
        Route::get('/perolehan-marketing', [LaporanPerolehanMarketingController::class, 'index'])->name('perolehan-marketing');
        Route::get('/perolehan-marketing/{userId}/detail', [LaporanPerolehanMarketingController::class, 'detail'])->name('perolehan-marketing.detail');
    });

    // Laporan Fee Telemarketing - Manager HRD, HRD, Manager Telemarketing, Telemarketing
    Route::middleware(['role:superadmin,admin,manager hrd,hrd,manager telemarketing,telemarketing'])->group(function () {
        Route::get('/perolehan-telemarketing', [LaporanPerolehanTelemarketingController::class, 'index'])->name('perolehan-telemarketing');
        Route::get('/perolehan-telemarketing/{userId}/detail', [LaporanPerolehanTelemarketingController::class, 'detail'])->name('perolehan-telemarketing.detail');
    });

    // Laporan Daftar & Herregistrasi - Manager HRD, HRD, Manager Wilayah, Marketing
    Route::middleware(['role:superadmin,admin,manager hrd,hrd,manager wilayah,marketing'])->group(function () {
        Route::get('/daftar-herregistrasi', [LaporanDaftarHerregistrasiController::class, 'index'])->name('daftar-herregistrasi');
    });

    // Laporan Alokasi - Manager Keuangan & Keuangan
    Route::middleware(['role:superadmin,admin,manager keuangan,keuangan'])->group(function () {
        Route::get('/alokasi-pendaftaran', [LaporanAlokasiPendaftaranController::class, 'pendaftaran'])->name('alokasi-pendaftaran');
        Route::post('/alokasi-pendaftaran/preview', [LaporanAlokasiPendaftaranController::class, 'previewPdf'])->name('alokasi-pendaftaran.preview');

        Route::get('/alokasi-herregistrasi', [LaporanAlokasiHerregistrasiController::class, 'index'])->name('alokasi-herregistrasi');
        Route::get('/alokasi-herregistrasi/pdf', [LaporanAlokasiHerregistrasiController::class, 'exportPdf'])->name('alokasi-herregistrasi.pdf');
        Route::post('/alokasi-herregistrasi/preview', [LaporanAlokasiHerregistrasiController::class, 'previewPdf'])->name('alokasi-herregistrasi.preview');

        Route::get('/alokasi-angsuran', [LaporanAlokasiAngsuranController::class, 'index'])->name('alokasi-angsuran');
        Route::post('/alokasi-angsuran/preview', [LaporanAlokasiAngsuranController::class, 'previewPdf'])->name('alokasi-angsuran.preview');
    });
});

/*
|--------------------------------------------------------------------------
| Role: SUPERADMIN, ADMIN, AUDIT, VALIDATOR  (Log Aktivitas)
|--------------------------------------------------------------------------
*/
Route::middleware(['auth', 'role:superadmin,admin,audit,validator'])->group(function () {
    Route::get('/log-aktivitas', [LogAktivitasController::class, 'index'])->name('log-aktivitas.index');
    Route::get('/log-aktivitas/{id}/detail', [LogAktivitasController::class, 'detail'])->name('log-aktivitas.detail');
});

require __DIR__ . '/auth.php';
