<?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\Web\Auth\FindIdController;
use App\Http\Controllers\Web\Auth\FindPasswordController;
use App\Http\Controllers\Web\Cs\NoticeController;

Route::view('/', 'web.home')->name('web.home');

/*
|--------------------------------------------------------------------------
| CS
|--------------------------------------------------------------------------
*/
Route::prefix('cs')->name('web.cs.')->group(function () {
    Route::get('/notice', [NoticeController::class, 'index'])->name('notice.index');
    Route::get('/notice/{seq}', [NoticeController::class, 'show'])->whereNumber('seq')->name('notice.show');
    Route::view('faq',    'web.cs.faq.index')->name('faq.index');
    Route::view('kakao',  'web.cs.kakao.index')->name('kakao.index');
    Route::view('qna',    'web.cs.qna.index')->name('qna.index');
    Route::view('guide',  'web.cs.guide.index')->name('guide.index');
});

/*
|--------------------------------------------------------------------------
| My Page
|--------------------------------------------------------------------------
*/
Route::prefix('mypage')->name('web.mypage.')->group(function () {
    Route::view('info',     'web.mypage.info.index')->name('info.index');
    Route::view('usage',    'web.mypage.usage.index')->name('usage.index');
    Route::view('exchange', 'web.mypage.exchange.index')->name('exchange.index');
    Route::view('qna',      'web.mypage.qna.index')->name('qna.index');
});

/*
|--------------------------------------------------------------------------
| Policy
|--------------------------------------------------------------------------
*/
Route::prefix('policy')->name('web.policy.')->group(function () {
    Route::view('/',        'web.policy.index')->name('index');
    Route::view('privacy',  'web.policy.privacy.index')->name('privacy.index');
    Route::view('terms',    'web.policy.terms.index')->name('terms.index');
    Route::view('email',    'web.policy.email.index')->name('email.index');
});

/*
|--------------------------------------------------------------------------
| Auth
|--------------------------------------------------------------------------
*/
Route::prefix('auth')->name('web.auth.')->group(function () {

    // 정적 페이지 (컨트롤러 불필요)
    Route::view('login',    'web.auth.login')->name('login');
    Route::view('register', 'web.auth.register')->name('register');

    // 아이디 찾기 (컨트롤러)
    Route::get('find-id',           [FindIdController::class, 'show'])->name('find_id');
    Route::post('find-id/send-code',[FindIdController::class, 'sendCode'])->name('find_id.send_code');
    Route::post('find-id/verify',   [FindIdController::class, 'verify'])->name('find_id.verify');
    Route::post('find-id/reset',    [FindIdController::class, 'reset'])->name('find_id.reset');

    // 비밀번호 찾기 (컨트롤러)
    Route::get('find-password',            [FindPasswordController::class, 'show'])->name('find_password');
    Route::post('find-password/send-code', [FindPasswordController::class, 'sendCode'])->name('find_password.send_code');
    Route::post('find-password/verify',    [FindPasswordController::class, 'verify'])->name('find_password.verify');
    Route::post('find-password/reset',     [FindPasswordController::class, 'reset'])->name('find_password.reset');
    Route::post('find-password/reset-session', [FindPasswordController::class, 'resetSession'])->name('find_password.reset_session');
});

/*
|--------------------------------------------------------------------------
| Legacy redirects
|--------------------------------------------------------------------------
*/
Route::get('/login', fn() => redirect()->route('web.auth.login'))->name('web.login');
Route::get('/register', fn() => redirect()->route('web.auth.register'))->name('web.signup');

// Dev Lab (로컬에서만 + 파일 존재할 때만 라우트 등록)
if (app()->environment(['local', 'development', 'testing'])
    && class_exists(\App\Http\Controllers\Dev\DevLabController::class)) {

    Route::prefix('__dev')->name('dev.')->group(function () {
        Route::get('/lab', [\App\Http\Controllers\Dev\DevLabController::class, 'index'])->name('lab');

        Route::post('/lab/mail', [\App\Http\Controllers\Dev\DevLabController::class, 'mail'])->name('lab.mail');
        Route::post('/lab/mail-raw', [\App\Http\Controllers\Dev\DevLabController::class, 'mailRaw'])->name('lab.mail_raw');
        Route::post('/lab/sms',  [\App\Http\Controllers\Dev\DevLabController::class, 'sms'])->name('lab.sms');
        Route::post('/lab/db',   [\App\Http\Controllers\Dev\DevLabController::class, 'db'])->name('lab.db');

        Route::post('/lab/session/set',    [\App\Http\Controllers\Dev\DevLabController::class, 'sessionSet'])->name('lab.session.set');
        Route::post('/lab/session/get',    [\App\Http\Controllers\Dev\DevLabController::class, 'sessionGet'])->name('lab.session.get');
        Route::post('/lab/session/forget', [\App\Http\Controllers\Dev\DevLabController::class, 'sessionForget'])->name('lab.session.forget');
        Route::post('/lab/session/flush',  [\App\Http\Controllers\Dev\DevLabController::class, 'sessionFlush'])->name('lab.session.flush');
    });
}

Route::fallback(fn () => abort(404));
