<?php

use App\Http\Controllers\Page\AgenciesController;
use App\Http\Controllers\Page\AgencyPageController;
use App\Http\Controllers\Page\AgencyRegistrationController;
use App\Http\Controllers\Page\AuthController;
use App\Http\Controllers\Page\ContactController;
use App\Http\Controllers\Page\HomeController;
use App\Http\Controllers\Page\PublicResourceScheduleController;
use Illuminate\Support\Facades\Route;

require __DIR__ . '/admin.php';
require __DIR__ . '/agency.php';

// Public kaynak (rehber/şoför) takvimi — auth gerektirmez, token ile erişilir
Route::get('/resource-schedule/{token}', [PublicResourceScheduleController::class, 'show'])->name('public.resource.schedule');

// Ana sayfa
Route::get('/', [HomeController::class, 'index'])->name('home');
Route::get('/agencies', [AgenciesController::class, 'index'])->name('customer.agencies');

// Customer Agency
Route::prefix('agency')->name('agency.')->group(function () {
    Route::get('register', [AgencyRegistrationController::class, 'showRegisterForm'])->name('register');
    Route::post('register', [AgencyRegistrationController::class, 'register']);
});

// Agency Routes
Route::prefix('agency/{agency:slug}')->name('customer.agency.')->group(function () {
    Route::get('/', [AgencyPageController::class, 'show'])->name('show');
    Route::get('/tours/search', [AgencyPageController::class, 'searchTours'])->name('tours.search');
    Route::get('/tours/{type}', [AgencyPageController::class, 'listTours'])->name('tours.list');
    Route::get('/tours/{type}/{slug}', [AgencyPageController::class, 'showTour'])->name('tours.detail');
});

// Customer Auth Routes
Route::prefix('customer')->name('customer.')->group(function () {
    Route::middleware('guest')->group(function () {
        Route::get('register', [AuthController::class, 'showRegisterForm'])->name('register');
        Route::post('register', [AuthController::class, 'register']);
        Route::get('login', [AuthController::class, 'showLoginForm'])->name('login');
        Route::post('login', [AuthController::class, 'login']);
        Route::get('forgot-password', [AuthController::class, 'showForgotPasswordForm'])->name('password.request');
        Route::post('forgot-password', [AuthController::class, 'sendResetLink'])->name('password.email');
        Route::get('reset-password/{token}', [AuthController::class, 'showResetPasswordForm'])->name('password.reset');
        Route::post('reset-password', [AuthController::class, 'resetPassword'])->name('password.update');
    });

    Route::middleware('auth')->group(function () {
        Route::post('logout', [AuthController::class, 'logout'])->name('logout');
        Route::get('dashboard', function () {
            return view('customer.dashboard');
        })->name('dashboard');
    });
});

// Contact form
Route::post('/contact/submit', [ContactController::class, 'submit'])->name('customer.contact.submit');
