<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\AdminController;
use App\Http\Controllers\Admin\RolePermissionController;
use App\Http\Controllers\Admin\CategoryController;
use App\Http\Controllers\Admin\TvCategoryController;
use App\Http\Controllers\Admin\MatchCategoryController;
use App\Http\Controllers\Admin\RadioCategoryController;
use App\Http\Controllers\Admin\VideoController;
use App\Http\Controllers\Admin\SliderController;
use App\Http\Controllers\Admin\TvController;
use App\Http\Controllers\Admin\RadioController;
use App\Http\Controllers\Admin\MatchController;
use App\Http\Controllers\Admin\NotificationController;
use App\Http\Controllers\Admin\PageController;
use App\Http\Controllers\Admin\EmailSettingController;
use App\Http\Controllers\Admin\Settings\NotificationController as NotificationSettingsController;
use App\Http\Controllers\Admin\Settings\AdvertisementController as AdvertisementSettingsController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Admin\SeriesController;
use App\Http\Controllers\Admin\SeasonController;
use App\Http\Controllers\Admin\EpisodeController;
use App\Http\Controllers\Admin\SubscriptionPlanController;
use App\Http\Controllers\Admin\PaymentGatewayController;

Route::redirect('/', 'admin/login');

Route::prefix('admin')->name('admin.')->middleware(['admin'])->group(function() {
    // Dashboard Route
    Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard');
    
    // Admin Routes
    Route::get('/admins', [AdminController::class, 'index'])->name('admins.index');
    Route::get('/admins/add', [AdminController::class, 'add'])->name('admins.add');
    Route::post('/admins/add', [AdminController::class, 'insert'])->name('admins.insert');
    Route::get('/admins/{id}/edit', [AdminController::class, 'edit'])->name('admins.edit');
    Route::post('/admins/edit', [AdminController::class, 'update'])->name('admins.update');
    Route::delete('/admins/{id}', [AdminController::class, 'delete'])->name('admins.delete');

    // Roles & Permission Routes
    Route::get('/roles', [RolePermissionController::class, 'index'])->name('roles.index');
    Route::get('/roles/add', [RolePermissionController::class, 'add'])->name('roles.add');
    Route::post('/roles/add', [RolePermissionController::class, 'insert'])->name('roles.insert');
    Route::get('/roles/{id}/edit', [RolePermissionController::class, 'edit'])->name('roles.edit');
    Route::post('/roles/edit', [RolePermissionController::class, 'update'])->name('roles.update');
    Route::delete('/roles/{id}', [RolePermissionController::class, 'delete'])->name('roles.delete');

    // Category Routes
    Route::get('/categories', [CategoryController::class, 'index'])->name('categories.index');
    Route::post('/categories/add', [CategoryController::class, 'add'])->name('categories.add');
    Route::get('/categories/{id}', [CategoryController::class, 'getCategoryById']);
    Route::post('/categories/edit', [CategoryController::class, 'update'])->name('categories.update');
    Route::delete('/categories/{id}', [CategoryController::class, 'delete'])->name('categories.delete');

    // Video Routes
    Route::get('/videos', [VideoController::class, 'index'])->name('videos.index');
    Route::get('/videos/add', [VideoController::class, 'add'])->name('videos.add');
    Route::post('/videos/add', [VideoController::class, 'insert'])->name('videos.insert');
    Route::get('/videos/{id}/edit', [VideoController::class, 'edit'])->name('videos.edit');
    Route::post('/videos/edit', [VideoController::class, 'update'])->name('videos.update');
    Route::delete('/videos/{id}', [VideoController::class, 'delete'])->name('videos.delete');

    // Slider Routes
    Route::get('/sliders', [SliderController::class, 'index'])->name('sliders.index');
    Route::get('/sliders/add', [SliderController::class, 'add'])->name('sliders.add');
    Route::post('/sliders/add', [SliderController::class, 'insert'])->name('sliders.insert');
    Route::get('/sliders/{id}/edit', [SliderController::class, 'edit'])->name('sliders.edit');
    Route::post('/sliders/edit', [SliderController::class, 'update'])->name('sliders.update');
    Route::delete('/sliders/{id}', [SliderController::class, 'delete'])->name('sliders.delete');

    // TV Category Routes
    Route::get('/tv-categories', [TvCategoryController::class, 'index'])->name('tv-categories.index');
    Route::post('/tv-categories/add', [TvCategoryController::class, 'add'])->name('tv-categories.add');
    Route::get('/tv-categories/{id}', [TvCategoryController::class, 'getTvCategoryById']);
    Route::post('/tv-categories/edit', [TvCategoryController::class, 'update'])->name('tv-categories.update');
    Route::delete('/tv-categories/{id}', [TvCategoryController::class, 'delete'])->name('tv-categories.delete');

    // TV Routes
    Route::get('/tvs', [TvController::class, 'index'])->name('tvs.index');
    Route::get('/tvs/add', [TvController::class, 'add'])->name('tvs.add');
    Route::post('/tvs/add', [TvController::class, 'insert'])->name('tvs.insert');
    Route::get('/tvs/{id}/edit', [TvController::class, 'edit'])->name('tvs.edit');
    Route::post('/tvs/edit', [TvController::class, 'update'])->name('tvs.update');
    Route::delete('/tvs/{id}', [TvController::class, 'delete'])->name('tvs.delete');

    // Radio Category Routes
    Route::get('/radio-categories', [RadioCategoryController::class, 'index'])->name('radio-categories.index');
    Route::post('/radio-categories/add', [RadioCategoryController::class, 'add'])->name('radio-categories.add');
    Route::get('/radio-categories/{id}', [RadioCategoryController::class, 'getRadioCategoryById']);
    Route::post('/radio-categories/edit', [RadioCategoryController::class, 'update'])->name('radio-categories.update');
    Route::delete('/radio-categories/{id}', [RadioCategoryController::class, 'delete'])->name('radio-categories.delete');

    // Radio Routes
    Route::get('/radios', [RadioController::class, 'index'])->name('radios.index');
    Route::get('/radios/add', [RadioController::class, 'add'])->name('radios.add');
    Route::post('/radios/add', [RadioController::class, 'insert'])->name('radios.insert');
    Route::get('/radios/{id}/edit', [RadioController::class, 'edit'])->name('radios.edit');
    Route::post('/radios/edit', [RadioController::class, 'update'])->name('radios.update');
    Route::delete('/radios/{id}', [RadioController::class, 'delete'])->name('radios.delete');

    // Match Routes
    Route::get('/matches', [MatchController::class, 'index'])->name('matches.index');
    Route::get('/matches/add', [MatchController::class, 'add'])->name('matches.add');
    Route::post('/matches/add', [MatchController::class, 'insert'])->name('matches.insert');
    Route::get('/matches/{id}/edit', [MatchController::class, 'edit'])->name('matches.edit');
    Route::post('/matches/edit', [MatchController::class, 'update'])->name('matches.update');
    Route::delete('/matches/{id}', [MatchController::class, 'delete'])->name('matches.delete');

    // App Users Routes
    Route::get('/users', [UserController::class, 'index'])->name('users.index');
    Route::post('/users/{id}/toggle-status', [UserController::class, 'toggleStatus'])->name('users.toggle-status');
    Route::delete('/users/{id}', [UserController::class, 'delete'])->name('users.delete');

    // Series Routes
    Route::get('/series', [SeriesController::class, 'index'])->name('series.index');
    Route::get('/series/add', [SeriesController::class, 'add'])->name('series.add');
    Route::post('/series/add', [SeriesController::class, 'insert'])->name('series.insert');
    Route::get('/series/{id}/edit', [SeriesController::class, 'edit'])->name('series.edit');
    Route::post('/series/edit', [SeriesController::class, 'update'])->name('series.update');
    Route::delete('/series/{id}', [SeriesController::class, 'delete'])->name('series.delete');

    // Season Routes (nested under series)
    Route::get('/series/{seriesId}/seasons', [SeasonController::class, 'index'])->name('seasons.index');
    Route::get('/series/{seriesId}/seasons/add', [SeasonController::class, 'add'])->name('seasons.add');
    Route::post('/series/{seriesId}/seasons/add', [SeasonController::class, 'insert'])->name('seasons.insert');
    Route::get('/series/{seriesId}/seasons/{id}/edit', [SeasonController::class, 'edit'])->name('seasons.edit');
    Route::post('/series/{seriesId}/seasons/{id}/edit', [SeasonController::class, 'update'])->name('seasons.update');
    Route::delete('/series/{seriesId}/seasons/{id}', [SeasonController::class, 'delete'])->name('seasons.delete');

    // Episode Routes (nested under series/season)
    Route::get('/series/{seriesId}/seasons/{seasonId}/episodes', [EpisodeController::class, 'index'])->name('episodes.index');
    Route::get('/series/{seriesId}/seasons/{seasonId}/episodes/add', [EpisodeController::class, 'add'])->name('episodes.add');
    Route::post('/series/{seriesId}/seasons/{seasonId}/episodes/add', [EpisodeController::class, 'insert'])->name('episodes.insert');
    Route::get('/series/{seriesId}/seasons/{seasonId}/episodes/{id}/edit', [EpisodeController::class, 'edit'])->name('episodes.edit');
    Route::post('/series/{seriesId}/seasons/{seasonId}/episodes/{id}/edit', [EpisodeController::class, 'update'])->name('episodes.update');
    Route::delete('/series/{seriesId}/seasons/{seasonId}/episodes/{id}', [EpisodeController::class, 'delete'])->name('episodes.delete');

    // Subscription Plan Routes
    Route::get('/subscription-plans', [SubscriptionPlanController::class, 'index'])->name('subscription-plans.index');
    Route::get('/subscription-plans/add', [SubscriptionPlanController::class, 'add'])->name('subscription-plans.add');
    Route::post('/subscription-plans/add', [SubscriptionPlanController::class, 'insert'])->name('subscription-plans.insert');
    Route::get('/subscription-plans/{id}/edit', [SubscriptionPlanController::class, 'edit'])->name('subscription-plans.edit');
    Route::post('/subscription-plans/edit', [SubscriptionPlanController::class, 'update'])->name('subscription-plans.update');
    Route::delete('/subscription-plans/{id}', [SubscriptionPlanController::class, 'delete'])->name('subscription-plans.delete');

    // User Subscriptions management
    Route::get('/user-subscriptions', [SubscriptionPlanController::class, 'userSubscriptions'])->name('user-subscriptions.index');
    Route::post('/user-subscriptions/grant', [SubscriptionPlanController::class, 'grantSubscription'])->name('user-subscriptions.grant');
    Route::delete('/user-subscriptions/{id}', [SubscriptionPlanController::class, 'cancelSubscription'])->name('user-subscriptions.cancel');

    // Notification Routes
    Route::get('/notifications', [NotificationController::class, 'index'])->name('notifications.index');
    Route::post('/notifications/send', [NotificationController::class, 'sendNotification'])->name('notifications.send');

    // Page Routes
    Route::get('/pages', [PageController::class, 'index'])->name('pages.index');
    Route::get('/pages/add', [PageController::class, 'add'])->name('pages.add');
    Route::post('/pages/add', [PageController::class, 'insert'])->name('pages.insert');
    Route::get('/pages/{id}/edit', [PageController::class, 'edit'])->name('pages.edit');
    Route::post('/pages/edit', [PageController::class, 'update'])->name('pages.update');
    Route::delete('/pages/{id}', [PageController::class, 'delete'])->name('pages.delete');

    // Email Settings Routes
    Route::get('/email/configuration', [EmailSettingController::class, 'editEmailConfiguration'])->name('email.configuration'); 
    Route::post('/email/configuration/edit', [EmailSettingController::class, 'updateEmailConfiguration'])->name('email.configuration.update'); 
    Route::get('/email/templates', [EmailSettingController::class, 'index'])->name('email.templates.index');
    Route::get('/email/templates/{id}/edit', [EmailSettingController::class, 'edit'])->name('email.templates.edit'); 
    Route::post('/email/templates/edit', [EmailSettingController::class, 'update'])->name('email.templates.update'); 
    Route::get('/email/global-template', [EmailSettingController::class, 'editEmailGlobalTemplate'])->name('email.global-template'); 
    Route::post('/email/global-template/edit', [EmailSettingController::class, 'updateEmailGlobalTemplate'])->name('email.global-template.update'); 

    // Payment Gateway Settings Routes
    Route::get('/settings/payment-gateways', [PaymentGatewayController::class, 'index'])->name('payment-gateways.index');
    Route::post('/settings/payment-gateways/{gateway}', [PaymentGatewayController::class, 'update'])->name('payment-gateways.update');

    // Settings Routes
    Route::controller(NotificationSettingsController::class)->group(function () {
        Route::get('/settings/notification', 'notificationSettingsView')->name('settings.notification');
        Route::post('/settings/upload/firebase-credentials', 'uploadFirebaseCredentials')->name('settings.upload.firebase.credentials');
    });
    Route::controller(AdvertisementSettingsController::class)->group(function () {
        Route::get('/settings/advertisement', 'advertisementSettingsView')->name('settings.advertisement');
        Route::post('/settings/advertisement/edit', 'updateAdvertisement')->name('settings.advertisement.update');
    });

});


