<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PageController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\WeddingController;
use App\Http\Controllers\GuestController;
use App\Http\Controllers\InvitationController;
use App\Http\Controllers\BookingController;
use App\Http\Controllers\ServiceController;
use App\Http\Controllers\SubscriptionController;
use App\Http\Controllers\SettingsController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\AuthController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

// ==================== PUBLIC ROUTES ====================
Route::get('/', [PageController::class, 'landing'])->name('landing');

// Guest Wedding Page View (Public)
Route::get('/wedding/{slug}', [WeddingController::class, 'publicView'])->name('wedding.public');
Route::post('/wedding/{slug}/rsvp', [WeddingController::class, 'rsvp'])->name('wedding.rsvp');
Route::post('/wedding/{slug}/book', [WeddingController::class, 'book'])->name('wedding.book');

// Authentication Routes
Route::get('/login', [AuthController::class, 'showLogin'])->name('login');
Route::post('/login', [AuthController::class, 'login']);
Route::get('/register', [AuthController::class, 'showRegister'])->name('register');
Route::post('/register', [AuthController::class, 'register']);
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');

// ==================== COUPLE ROUTES ====================
// Dashboard
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

// Wedding Management
Route::prefix('wedding')->name('wedding.')->group(function () {
    Route::get('/page', [WeddingController::class, 'page'])->name('page');
    Route::post('/page/update', [WeddingController::class, 'updatePage'])->name('page.update');
    Route::get('/preview', [WeddingController::class, 'preview'])->name('preview');
    Route::post('/custom-url', [WeddingController::class, 'updateCustomUrl'])->name('custom-url');
    Route::post('/schedule', [WeddingController::class, 'updateSchedule'])->name('schedule');
});

// Guest Management
Route::prefix('guests')->name('guests.')->group(function () {
    Route::get('/', [GuestController::class, 'index'])->name('index');
    Route::get('/create', [GuestController::class, 'create'])->name('create');
    Route::post('/store', [GuestController::class, 'store'])->name('store');
    Route::get('/{id}/edit', [GuestController::class, 'edit'])->name('edit');
    Route::put('/{id}', [GuestController::class, 'update'])->name('update');
    Route::delete('/{id}', [GuestController::class, 'destroy'])->name('destroy');
    Route::post('/import', [GuestController::class, 'import'])->name('import');
    Route::get('/export/csv', [GuestController::class, 'exportCsv'])->name('export.csv');
    Route::get('/export/excel', [GuestController::class, 'exportExcel'])->name('export.excel');
    Route::post('/bulk-action', [GuestController::class, 'bulkAction'])->name('bulk-action');
});

// Invitation Management
Route::prefix('invitations')->name('invitations.')->group(function () {
    Route::get('/', [InvitationController::class, 'index'])->name('index');
    Route::post('/send', [InvitationController::class, 'send'])->name('send');
    Route::post('/send-bulk', [InvitationController::class, 'sendBulk'])->name('send-bulk');
    Route::post('/resend/{id}', [InvitationController::class, 'resend'])->name('resend');
    Route::get('/template', [InvitationController::class, 'template'])->name('template');
    Route::post('/template/update', [InvitationController::class, 'updateTemplate'])->name('template.update');
    Route::get('/statistics', [InvitationController::class, 'statistics'])->name('statistics');
});

// Booking Management
Route::prefix('bookings')->name('bookings.')->group(function () {
    Route::get('/', [BookingController::class, 'index'])->name('index');
    Route::get('/{id}', [BookingController::class, 'show'])->name('show');
    Route::put('/{id}/confirm', [BookingController::class, 'confirm'])->name('confirm');
    Route::put('/{id}/cancel', [BookingController::class, 'cancel'])->name('cancel');
    Route::delete('/{id}', [BookingController::class, 'destroy'])->name('destroy');
    Route::get('/export/all', [BookingController::class, 'exportAll'])->name('export');
    Route::get('/accommodation', [BookingController::class, 'accommodation'])->name('accommodation');
    Route::get('/transport', [BookingController::class, 'transport'])->name('transport');
    Route::get('/activities', [BookingController::class, 'activities'])->name('activities');
});

// Services Management
Route::prefix('services')->name('services.')->group(function () {
    Route::get('/', [ServiceController::class, 'index'])->name('index');
    Route::get('/create', [ServiceController::class, 'create'])->name('create');
    Route::post('/store', [ServiceController::class, 'store'])->name('store');
    Route::get('/{id}/edit', [ServiceController::class, 'edit'])->name('edit');
    Route::put('/{id}', [ServiceController::class, 'update'])->name('update');
    Route::delete('/{id}', [ServiceController::class, 'destroy'])->name('destroy');
    Route::post('/{id}/capacity', [ServiceController::class, 'updateCapacity'])->name('update-capacity');
});

// Subscription Management
Route::prefix('subscription')->name('subscription.')->group(function () {
    Route::get('/', [SubscriptionController::class, 'index'])->name('index');
    Route::get('/plans', [SubscriptionController::class, 'plans'])->name('plans');
    Route::post('/subscribe/{plan}', [SubscriptionController::class, 'subscribe'])->name('subscribe');
    Route::post('/cancel', [SubscriptionController::class, 'cancel'])->name('cancel');
    Route::get('/invoice/{id}', [SubscriptionController::class, 'invoice'])->name('invoice');
    Route::get('/payment-methods', [SubscriptionController::class, 'paymentMethods'])->name('payment-methods');
    Route::post('/payment-method/add', [SubscriptionController::class, 'addPaymentMethod'])->name('add-payment-method');
});

// Settings
// Settings
Route::prefix('settings')->name('settings.')->group(function () {
    Route::get('/', [SettingsController::class, 'index'])->name('index');
    Route::put('/profile', [SettingsController::class, 'updateProfile'])->name('update-profile');
    Route::put('/password', [SettingsController::class, 'updatePassword'])->name('update-password');
    Route::put('/notifications', [SettingsController::class, 'updateNotifications'])->name('update-notifications');
    Route::post('/avatar', [SettingsController::class, 'uploadAvatar'])->name('upload-avatar');
    Route::delete('/account', [SettingsController::class, 'deleteAccount'])->name('delete-account');
    Route::get('/export-data', [SettingsController::class, 'exportData'])->name('export-data');
    Route::get('/2fa', [SettingsController::class, 'twoFactorAuth'])->name('2fa');
    Route::get('/sessions', [SettingsController::class, 'sessions'])->name('sessions');
    Route::get('/login-activity', [SettingsController::class, 'loginActivity'])->name('login-activity');
});

// ==================== ADMIN ROUTES ====================
// ==================== ADMIN ROUTES ====================
Route::prefix('admin')->name('admin.')->group(function () {
    Route::get('/dashboard', [AdminController::class, 'dashboard'])->name('dashboard');
    
    // User Management
    Route::prefix('users')->name('users.')->group(function () {
        Route::get('/', [AdminController::class, 'users'])->name('index');
        Route::get('/create', [AdminController::class, 'createUser'])->name('create');
        Route::post('/store', [AdminController::class, 'storeUser'])->name('store');
        Route::get('/{id}/edit', [AdminController::class, 'editUser'])->name('edit');
        Route::put('/{id}', [AdminController::class, 'updateUser'])->name('update');
        Route::get('/{id}', [AdminController::class, 'userShow'])->name('show');
        Route::post('/{id}/suspend', [AdminController::class, 'suspendUser'])->name('suspend');
        Route::post('/{id}/activate', [AdminController::class, 'activateUser'])->name('activate');
        Route::delete('/{id}', [AdminController::class, 'deleteUser'])->name('delete');
    });
    
    // Subscription Plans Management
    Route::prefix('plans')->name('plans.')->group(function () {
        Route::get('/', [AdminController::class, 'plans'])->name('index');
        Route::get('/create', [AdminController::class, 'createPlan'])->name('create');
        Route::post('/store', [AdminController::class, 'storePlan'])->name('store');
        Route::get('/{id}/edit', [AdminController::class, 'editPlan'])->name('edit');
        Route::put('/{id}', [AdminController::class, 'updatePlan'])->name('update');
        Route::delete('/{id}', [AdminController::class, 'deletePlan'])->name('delete');
    });
    
    // Weddings Management - ADD ALL THESE ROUTES
    Route::prefix('weddings')->name('weddings.')->group(function () {
        Route::get('/', [AdminController::class, 'weddings'])->name('index');
        Route::get('/create', [AdminController::class, 'createWedding'])->name('create');
        Route::post('/store', [AdminController::class, 'storeWedding'])->name('store');
        Route::get('/{id}/edit', [AdminController::class, 'editWedding'])->name('edit');
        Route::put('/{id}', [AdminController::class, 'updateWedding'])->name('update');
        Route::get('/{id}', [AdminController::class, 'weddingShow'])->name('show');
        Route::delete('/{id}', [AdminController::class, 'deleteWedding'])->name('delete');
    });
    
    // Analytics & Reports
    Route::get('/analytics', [AdminController::class, 'analytics'])->name('analytics');
    Route::get('/reports', [AdminController::class, 'reports'])->name('reports');
    Route::get('/reports/download/{type}', [AdminController::class, 'downloadReport'])->name('reports.download');
    
    // System Settings
    Route::prefix('system')->name('system.')->group(function () {
        Route::get('/', [AdminController::class, 'systemSettings'])->name('index');
        Route::put('/update', [AdminController::class, 'updateSystemSettings'])->name('update');
        Route::post('/clear-cache', [AdminController::class, 'clearCache'])->name('clear-cache');
    });
    
    // Support Management
    Route::prefix('support')->name('support.')->group(function () {
        Route::get('/tickets', [AdminController::class, 'supportTickets'])->name('tickets');
        Route::get('/ticket/{id}', [AdminController::class, 'ticketShow'])->name('ticket.show');
        Route::post('/ticket/{id}/reply', [AdminController::class, 'replyTicket'])->name('ticket.reply');
        Route::post('/ticket/{id}/close', [AdminController::class, 'closeTicket'])->name('ticket.close');
    });
});


// ==================== API ROUTES (for AJAX) ====================
Route::prefix('api')->group(function () {
    Route::get('/guests/search', [GuestController::class, 'search'])->name('api.guests.search');
    Route::get('/bookings/stats', [BookingController::class, 'stats'])->name('api.bookings.stats');
    Route::get('/dashboard/charts', [DashboardController::class, 'charts'])->name('api.dashboard.charts');
    Route::get('/invitations/stats', [InvitationController::class, 'statistics'])->name('api.invitations.stats');
});