<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\DropdownController;
use App\Http\Controllers\BusinessInformationController;
use App\Http\Controllers\PackageController;
use App\Http\Controllers\OrderController;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\PayPalController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\CloserController;
use App\Http\Controllers\LoginActivityController;
use App\Http\Controllers\CouponController;
use App\Http\Controllers\NMIController;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\RegisterController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


Route::get('/',['middleware' => 'guest', function () {
    return view('auth.login');
}]);

Route::post('/verify', [RegisterController::class, 'verifyuser'])->name('verify.verify');

Auth::routes(['verify'=>true]);

Route::group(['middleware' => ['auth']], function () {
    Route::get('/verify', function () {
        return view('auth.verify');
    })->name('verify.form');

    Route::post('/resend-otp',[RegisterController::class, 'resend_otp'])->name('resend-otp');
    Route::post('/change-phone-number',[RegisterController::class, 'change_phone_number'])->name('change-phone-number');

});

Route::group(['middleware' => ['auth','phone_verified']], function () {
    Route::get('/home', [HomeController::class, 'index'])->name('home');
    Route::get('/add-business-details', [HomeController::class, 'add_business_view'])->name('add-business-details');
    Route::get('/add-profile-details', [HomeController::class, 'add_profile_view'])->name('add-profile-details');
    Route::get('/select-package', [PackageController::class, 'index'])->name('select-package');
    Route::post('/add-radius',[BusinessInformationController::class,'business_info_radius'])->name('add-radius');
    Route::get('/check-closer',[CloserController::class,'check_closer'])->name('check-closer');
    Route::post('/business-details-insert',[BusinessInformationController::class,'business_info_insert'])->name('business-details-insert');
    // Route::get('/order/{id}',[OrderController::class,'order_view'])->name('order')
    Route::post('/order-submit',[OrderController::class,'order_submit'])->name('order-submit');
    Route::get('/order-completed',[OrderController::class,'ordercompleted'])->name('order-completed');
    Route::get('/orderdetail/{id}',[HomeController::class,'customer_order_view']);
    Route::post('/order',[OrderController::class,'order_view'])->name('order');

    // Route to check coupon code
    Route::get('/check-coupon',[CouponController::class,'check_coupon'])->name('check-coupon');
    Route::post('/add-product-coupon',[CouponController::class,'add_product_coupon'])->name('add-product-coupon');

    //routes to check business present or not
    Route::get('/check-business',[BusinessInformationController::class,'check_business'])->name('check-business');

    //edit business info
    Route::get('/edit-business-details', [BusinessInformationController::class, 'updatebusiness'])->name('edit-business-details');
    Route::post('/edit-radius',[BusinessInformationController::class,'business_info_update'])->name('edit-radius');
    Route::post('/business-update',[BusinessInformationController::class,'business_update'])->name('business-update');

    Route::get('change-password',[HomeController::class,'change_password'])->name('change-password');
    Route::post('password-changed',[HomeController::class,'password_changed'])->name('password_changed');
});

Route::controller(PaymentController::class)->group(function(){
    Route::get('checkout',[PaymentController::class,'stripe'])->name('checkout');
    // Route::get('stripe', 'stripe')
    Route::post('stripe', 'stripePost')->name('stripe.post');
});


// paypal routes

Route::get('/paypal', [PayPalController::class, 'paypal'])->name('paypal');
Route::get('payment', [PayPalController::class,'payment'])->name('payment');
Route::get('cancel', [PayPalController::class,'cancel'])->name('payment.cancel');
Route::get('payment/success', [PayPalController::class,'success'])->name('payment.success');


// admin routes
Route::prefix('admin')->middleware(['auth','isAdmin'])->group(function(){
    Route::get('dashboard', [AdminController::class, 'index'])->name('admindashboard');
    Route::get('allusers', [AdminController::class, 'userslist'])->name('allusers');
    Route::get('single-user/{id}', [AdminController::class, 'singleuser']);
    Route::post('admin-add-user',[AdminController::class,'add_user'])->name('admin-add-user');
    Route::get('orderslist', [AdminController::class, 'orderslist'])->name('orderslist');
    Route::get('view-order/{id}', [AdminController::class, 'order_invoice']);
    Route::get('invoice', [AdminController::class, 'invoice']);
    Route::get('login-activity',[AdminController::class, 'loginactivity'])->name('login-activity');
    Route::get('all-closers', [AdminController::class, 'closerslist'])->name('all-closers');
    Route::post('update-user', [AdminController::class, 'update_user'])->name('update-user');
    Route::post('change-to-closer',[AdminController::class, 'change_to_closer'])->name('change-to-closer');
    Route::get('closer-coupons/{id}',[AdminController::class, 'closer_coupons']);
    Route::get('coupons', [AdminController::class, 'coupons_list'])->name('coupons');
    Route::get('business-profiles', [AdminController::class, 'business_profiles'])->name('business-profiles');
    Route::get('single-business-profile/{bid}',[AdminController::class, 'single_business_profile']);
});

// closers routes
Route::prefix('closer')->middleware(['auth','isCloser'])->group(function(){
    Route::get('dashboard', [CloserController::class, 'index'])->name('closer-dashboard');
    Route::get('add-coupon', [CloserController::class, 'add_coupon'])->name('add-coupon');
    Route::post('insertcoupon', [CloserController::class, 'insert_coupon'])->name('insertcoupon');
    Route::get('closer-orders', [CloserController::class, 'show_orders'])->name('closer-orders');
    Route::get('orderdetails/{id}',[CloserController::class, 'view_order_detail'])->name('orderdetails');
    Route::post('add-comment',[CloserController::class,'add_comment'])->name('add-comment');
    Route::get('showcomments/{id}',[CloserController::class,'showcomments'])->name('showcomments');
});


//remove coupon
Route::get('remove-coupon/{id}',[CouponController::class,'remove_coupon'])->name('remove-coupon');
Route::get('removecoupon/{id}',[PackageController::class,'remove_coupon'])->name('removecoupon');
Route::post('update-product-coupon',[CouponController::class, 'update_product_coupon'])->name('update-product-coupon');
Route::get('404',[HomeController::class,'error_page'])->name('404');


//nmi payment

Route::get('nmiform',[NMIController::class,'nmiform'])->name('nmiform');

Route::post('/process-payment', [NMIController::class, 'processPayment'])->name('process.payment');

Route::get('/mark-as-read', [OrderController::class,'markAsRead'])->name('mark-as-read');
