<?php

use App\Http\Controllers\Admin\EbookController;
use App\Http\Controllers\AssignmentController;
use App\Http\Controllers\frontend\EbookReviewController;
use App\Http\Controllers\frontend\HomeController;
use App\Http\Controllers\student\BecomeInstructorController;
use App\Http\Controllers\student\BlogCommentController;
use App\Http\Controllers\student\BlogController;
use App\Http\Controllers\student\BootcampPurchaseController;
use App\Http\Controllers\student\CartController;
use App\Http\Controllers\student\CustomerSupportController;
use App\Http\Controllers\student\LiveClassController;
use App\Http\Controllers\student\MessageController;
use App\Http\Controllers\student\MyBootcampsController;
use App\Http\Controllers\student\MyCoursesController;
use App\Http\Controllers\student\MyEbookController;
use App\Http\Controllers\student\MyProfileController;
use App\Http\Controllers\student\MyTeamPackageController;
use App\Http\Controllers\student\OfflinePaymentController;
use App\Http\Controllers\student\PurchaseController;
use App\Http\Controllers\student\QuizController;
use App\Http\Controllers\student\ReviewController;
use App\Http\Controllers\student\TutorBookingController;
use App\Http\Controllers\student\WishListController;
use App\Http\Controllers\student\MyCourseBundleController;
use App\Http\Controllers\student\CourseBundlePurchaseController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth'])->group(function () {
    // my profile routes
    Route::controller(MyProfileController::class)->group(function () {
        Route::get('my-profile', 'index')->name('my.profile');
        Route::post('my-profile/update/{user_id}', 'update')->name('update.profile');
        Route::post('update-profile-picture', 'update_profile_picture')->name('update.profile.picture');
        Route::post('change-password', 'changePassword')->name('password.change');
    });

    // my wishlist routes
    Route::controller(WishListController::class)->group(function () {
        Route::get('wishlist', 'index')->name('wishlist');
        Route::get('toggleWishItem/{course_id?}', 'toggleWishItem')->name('toggleWishItem');
    });

    // my course routes
    Route::controller(MyCoursesController::class)->group(function () {
        Route::get('my-courses', 'index')->name('my.courses');
    });

    
     // course-bundle routes
    Route::controller(MyCourseBundleController::class)->group(function () {
        Route::get('my-course-bundles', 'index')->name('my.course.bundles');
        Route::get('my-course-bundles/details/{slug?}', 'show')->name('my.course.bundle.details');
        Route::get('my-course-bundles/invoice/{id}', 'invoice')->name('my.course.bundle.invoice');
        Route::get('my-course-bundles/purchase-history/{id}', 'purchaseHistory')->name('my.course.bundle.purchase.history');


        Route::post('course-bundle/rating/store{bundle_id}', 'store')->name('course.bundle.rating.store');
        Route::post('course-bundle/rating/update{id}', 'update')->name('course.bundle.rating.update');

    });
    Route::controller(CourseBundlePurchaseController::class)->group(function () {
        Route::get('purchase/course-bundle/{id}', 'purchase')->name('purchase.course.bundle');
        Route::get('course-bundle/purchase/history', 'purchase_history')->name('course.bundle.purchase.history');
        Route::get('course-bundle/invoice/{id}', 'invoice')->name('course.bundle.invoice');
    });



    // quiz routes
    Route::controller(QuizController::class)->group(function () {
        Route::post('quiz/submit/{id}', 'quiz_submit')->name('quiz.submit');
        Route::get('load/quiz/result/', 'load_result')->name('load.quiz.result');
        Route::get('load/quiz/questions/', 'load_questions')->name('load.quiz.questions');
    });

    // purchase routes
    Route::controller(PurchaseController::class)->group(function () {
        Route::get('purchase/course/{course_id}', 'purchase_course')->name('purchase.course');
        Route::post('payout', 'payout')->name('payout');
        Route::get('purchase-history', 'purchase_history')->name('purchase.history');
        Route::get('invoice/{id}', 'invoice')->name('invoice');
    });

    // cart routes
    Route::controller(CartController::class)->group(function () {
        Route::any('cart', 'index')->name('cart');
        Route::get('cart/store/{id}', 'store')->name('cart.store');
        Route::get('cart/delete/{id}', 'delete')->name('cart.delete');
    });

    // review routes
    Route::controller(ReviewController::class)->group(function () {
        Route::post('review/store', 'store')->name('review.store');
        Route::get('review/edit/', 'edit')->name('review.edit');
        Route::get('review/delete/{id}', 'delete')->name('review.delete');
        Route::post('review/update/{id}', 'update')->name('review.update');
        Route::get('review/like/{id}', 'like')->name('review.like');
        Route::get('review/dislike/{id}', 'dislike')->name('review.dislike');

        // review course routes
        Route::post('course/review/store', 'course_review_store')->name('course.review.store');
        Route::get('course/review/edit/', 'course_review_edit')->name('course.review.edit');
        Route::get('course/review/delete/{id}', 'course_review_delete')->name('course.review.delete');
        Route::post('course/course/review/update/{id}', 'course_review_update')->name('course.review.update');
        Route::get('course/review/like/{id}', 'course_review_like')->name('course.review.like');
        Route::get('course/review/dislike/{id}', 'course_review_dislike')->name('course.review.dislike');
    });

    // blog
    Route::controller(BlogController::class)->middleware('blog.visibility')->group(function () {
        Route::get('/blog-like', 'blog_like')->name('blog.like');
    });

    // blog comment
    Route::controller(BlogCommentController::class)->middleware('blog.visibility')->group(function () {
        Route::post('/blog/comment/store', 'store')->name('blog.comment.store');
        Route::get('/blog/comment/delete/{id}', 'delete')->name('blog.comment.delete');
        Route::post('/blog/comment/update/{id}', 'update')->name('blog.comment.update');
    });

    // message
    Route::controller(MessageController::class)->group(function () {
        Route::get('/message', 'index')->name('message');
        Route::post('/message/store', 'store')->name('message.store');
        Route::get('/message/fetch', 'fetch_message')->name('message.fetch');
        Route::post('/message/search/student', 'search_student')->name('search.student');
        Route::get('/message/inbox/{user_id}', 'inbox')->name('message.inbox');
    });

    // become instructor
    Route::controller(BecomeInstructorController::class)->group(function () {
        Route::get('/become-an-instructor', 'index')->name('become.instructor');
        Route::post('/become-an-instructor/store', 'store')->name('become.instructor.store');
    });

    // live class
    Route::controller(LiveClassController::class)->group(function () {
        Route::get('live-class/join/{id}', 'live_class_join')->name('live.class.join');
    });

    // Assignment Controller
    Route::controller(AssignmentController::class)->group(function () {
        Route::post('assignment_submit/store', 'assignment_submit')->name('student.assignment.submit');
        Route::get('assignment/download/{id}', 'download_result')->name('assignment.download.result');
    });

    // my bootcamp routes
    Route::controller(MyBootcampsController::class)->group(function () {
        Route::get('my-bootcamps/', 'index')->name('my.bootcamps');
        Route::get('my-bootcamps/details/{slug?}', 'show')->name('my.bootcamp.details');
        Route::get('my-bootcamps/invoice/{id}', 'invoice')->name('my.bootcamp.invoice');
        Route::get('bootcamp/live/class/join/{topic}', 'join_class')->name('bootcamp.live.class.join');
        Route::get('bootcamp/resource/download/{id}', 'download')->name('bootcamp.resource.download');
        Route::get('bootcamp/resource/play/{file}', 'play')->name('bootcamp.resource.play');
    });

    // purchase bootcamp routes
    Route::controller(BootcampPurchaseController::class)->group(function () {
        Route::get('purchase/bootcamp/{id}', 'purchase')->name('purchase.bootcamp');
        Route::get('bootcamp/purchase/history', 'purchase_history')->name('bootcamp.purchase.history');
        Route::get('bootcamp/invoice/{id}', 'invoice')->name('bootcamp.invoice');
    });

    // my team packages
    Route::controller(MyTeamPackageController::class)->group(function () {
        Route::get('my-team-packages/', 'index')->name('my.team.packages');
        Route::get('my-team-packages/details/{slug}', 'show')->name('my.team.packages.details')
            ->middleware('record.exists:team_training_packages,slug');
        Route::get('my-team-packages/search/members/{package_id?}', 'search_members')->name('search.package.members');
        Route::get('my-team-packages/{action}/members', 'member_action')->name('my.team.packages.members.action');
        Route::get('purchase/team-package/{id}', 'purchase')->name('purchase.team.package');
        Route::get('my-team-packages/invoice/{id}', 'invoice')->name('team.package.invoice')
            ->middleware('record.exists:team_package_purchases,id');
    });

    // tutor booking
    Route::controller(TutorBookingController::class)->group(function () {
        Route::get('my-bookings', 'my_bookings')->name('my_bookings');
        Route::get('booking-invoice/{id}', 'booking_invoice')->name('booking_invoice');
        Route::get('purchase/schedule/{id}', 'purchase')->name('purchase_schedule');
        Route::get('my-bookings/tution-class/join/{booking_id}', 'join_class')->name('tution_class.join');

        Route::post('tutor-review', 'tutor_review')->name('tutor_review');
    });

    // my ebook routes
    Route::controller(MyEbookController::class)->group(function () {
        Route::get('my-ebooks', 'index')->name('my.ebooks');
        Route::get('my-ebooks/{slug}/read', 'read')->name('my.ebooks.read');
    });

    // review routes
    Route::controller(EbookReviewController::class)->group(function () {
        Route::post('ebook/review/store', 'store')->name('ebook.review.store');
        Route::get('review/edit/', 'edit')->name('ebook.review.edit');
        Route::get('review/delete/{id}', 'delete')->name('review.delete');
        Route::post('review/update/{id}', 'update')->name('ebook.review.update');
    });

    // ebook paymentpreview
    Route::controller(EbookController::class)->group(function () {
        Route::get('ebook/payout/{id}', 'payout')->name('ebook.payout');
        // Route::get('payout', 'payout')->name('payout');
    });

    // ticket routes
    Route::controller(CustomerSupportController::class)->group(function () {
        // TICKET ROUTES
        Route::get('support/ticket/index', 'support_ticket_index')->name('support.ticket.index');
        Route::get('support/ticket/create', 'support_ticket_create')->name('support.ticket.create');
        Route::post('support/ticket/store', 'support_ticket_store')->name('support.ticket.store');

        // TICKET MESSAGE ROUTES
        Route::get('support/ticket/message/{ticket_thread_code?}', 'support_ticket_message')->name('support.ticket.message');
        Route::post('support/ticket/message/store', 'support_ticket_message_store')->name('support.ticket.message.store');

    });
});

//Certificate download
Route::get('certificate/{identifier}', [HomeController::class, 'download_certificate'])->name('certificate');

// offline payment
Route::post('payment/offline/store', [OfflinePaymentController::class, 'store'])->name('payment.offline.store');
