<?php

use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\VoucherController;
use App\Http\Controllers\VoucherCheckController;
use App\Http\Middleware\AdminAuth;
use Illuminate\Support\Facades\Route;

// Public: cek voucher
Route::get('/', [VoucherCheckController::class, 'index'])->name('voucher.check');
Route::post('/voucher/check', [VoucherCheckController::class, 'check'])->name('voucher.check.post');
Route::post('/voucher/use', [VoucherCheckController::class, 'use'])->name('voucher.use');

// Admin auth
Route::prefix('admin')->name('admin.')->group(function () {
    Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
    Route::post('/login', [AuthController::class, 'login'])->name('login.post');
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

    // Protected admin routes
    Route::middleware(AdminAuth::class)->group(function () {
        Route::resource('vouchers', VoucherController::class);
    });
});
