<?php

use Illuminate\Support\Facades\Route;

Route::namespace('User\Auth')
    ->name('user.')
    ->group(function () {
        Route::controller('LoginController')->group(function () {
            Route::get('/login', 'showLoginForm')->name('login');
            Route::post('/login', 'login');
            Route::get('logout', 'logout')->name('logout');
        });

        Route::controller('RegisterController')->group(function () {
            Route::get('register', 'showRegistrationForm')->name('register');
            Route::post('register', 'register')->middleware('registration.status');
            Route::post('check-mail', 'checkUser')->name('checkUser');
        });

        Route::controller('ForgotPasswordController')
            ->prefix('password')
            ->name('password.')
            ->group(function () {
                Route::get('reset', 'showLinkRequestForm')->name('request');
                Route::post('email', 'sendResetCodeEmail')->name('email');
                Route::get('code-verify', 'codeVerify')->name('code.verify');
                Route::post('verify-code', action: 'verifyCode')->name('verify.code');
            });
        Route::controller('ResetPasswordController')->group(function () {
            Route::post('password/reset', 'reset')->name('password.update');
            Route::get('password/reset/{token}', 'showResetForm')->name('password.reset');
        });
    });

Route::middleware('auth')
    ->name('user.')
    ->group(function () {
        //authorization
        Route::namespace('User')
            ->controller('AuthorizationController')
            ->group(function () {
                Route::get('authorization', 'authorizeForm')->name('authorization');
                Route::get('resend-verify/{type}', 'sendVerifyCode')->name('send.verify.code');
                Route::post('verify-email', 'emailVerification')->name('verify.email');
                Route::post('verify-mobile', 'mobileVerification')->name('verify.mobile');
                Route::post('verify-g2fa', 'g2faVerification')->name('go2fa.verify');
            });

        Route::middleware(['check.status'])->group(function () {
            Route::get('user-data', 'User\UserController@userData')->name('data');
            Route::post('user-data-submit', 'User\UserController@userDataSubmit')->name('data.submit');

            //KYC
            Route::get('kyc-form', 'User\UserController@kycForm')->name('kyc.form');
            Route::get('kyc-data', 'User\UserController@kycData')->name('kyc.data');
            Route::post('kyc-submit', 'User\UserController@kycSubmit')->name('kyc.submit');

            Route::middleware(['registration.complete', 'kyc'])
                ->namespace('User')
                ->group(function () {
                    Route::controller('UserController')->group(function () {
                        Route::get('dashboard', 'home')->name('home');

                        //2FA
                        Route::get('twofactor', 'show2faForm')->name('twofactor');
                        Route::post('twofactor/enable', 'create2fa')->name('twofactor.enable');
                        Route::post('twofactor/disable', 'disable2fa')->name('twofactor.disable');

                        //Balance Transfer
                        Route::get('/balance/transfer', 'balanceTransfer')->name('balance.transfer');
                        Route::post('/balance/transfer/receiver', 'balanceTransferUser')->name('balance.transfer.anotheruser');

                        //Commissions
                        Route::get('/referral/users', 'referralLog')->name('referral.log');
                        Route::get('/my-network/tree', 'myNetworkTree')->name('network.tree');
                        Route::get('/my-network/report', 'myNetworkReport')->name('network.report');
                        Route::get('/my-rewards/report', 'myRewardReport')->name('reward.report');
                        Route::get('/active-member/users', 'activeMember')->name('active.member');
                        Route::get('/partially-active/users', 'partiallyActiveMembers')->name('partial-active.member');
                        Route::get('/inactive-member/users', 'inactiveMember')->name('inactive.member');
                        Route::get('/reward-member/users', 'rewardMember')->name('reward.member');
                        Route::get('/my-network-excel', 'exportMyNetwork')->name('export.mynetwork');
                        Route::get('/reward-excel', 'exportReward')->name('export.rewardMember');
                        Route::get('/my-reward-excel', 'myRewardExcel')->name('export.my.reward');
                        Route::get('/inactive-member-excel', 'exportInactiveMember')->name('export.inactiveMember');
                        Route::get('/active-member-excel', 'exportActiveMember')->name('export.activeMember');
                        Route::get('/partially-active-member-excel', 'exportPartiallyActiveMember')->name('export.partiallyActiveMember');
                        Route::get('/my-network-pdf', 'generateMyNetworkPdf')->name('export.mynetwork.pdf');
                        Route::get('/reward-pdf', 'generateRewardPdf')->name('export.rewardMember.pdf');
                        Route::get('/my-reward-pdf', 'myRewardPdf')->name('export.my.reward.pdf');
                        Route::get('/my-active-members-pdf', 'generateActiveMemberPdf')->name('export.activeMember.pdf');
                        Route::get('/my-partially-active-members-pdf', 'generatePartiallyActiveMemberPdf')->name('export.partialActiveMember.pdf');
                        Route::get('/my-inactive-members-pdf', 'generateInactiveMemberPdf')->name('export.InactiveMember.pdf');

                        //Report
                        Route::any('deposit/history', 'depositHistory')->name('deposit.history');
                        Route::get('transactions', 'transactions')->name('transactions');
                        Route::get('generate-pdf', 'generatePdf')->name('transactions.pdf');
                        Route::get('export-transactions-excel', 'exportTransactionsExcel')->name('transactions.excel');

                        Route::get('attachment-download/{fil_hash}', 'attachmentDownload')->name('attachment.download');
                        Route::get('user-notification', 'userNotification')->name('notification');

                        Route::post('notification/mark-as-read', 'markAsRead')->name('notification.markAsRead');
                        Route::post('notification/mark-all-as-read', 'markAllAsRead')->name('notification.markAllAsRead');

                        Route::get('coupon', 'coupon')->name('coupon');

                        Route::get('notice-Board', 'noticeBoard')->name('noticeBoard');
                        Route::get('particular-notice/{id}', 'particularNotice')->name('particularNotice');

                        Route::get('download-app', 'app_link')->name('download-app');
                        Route::post('download-app-link', 'downloadAppLink')->name('download.app.link');
                        Route::get('download-plan-receipt/{id}', 'downloadReceipt')->name('plan.purchase.receipt');
                        Route::get('downloadables', 'downloadPdfList')->name('download.pdf');
                        Route::get('/downloadFile/{id}', 'downloadPdfList')->name('file.download');
                    });

                    Route::controller('PaymentsController')->group(function () {
                        Route::get('donations/received', 'paymentReceived')->name('donations.received');
                        Route::get('donations/paid', 'paymentPaid')->name('donations.paid');
                        Route::post('donations/store/{id?}', 'storePayments')->name('donations.store');
                        Route::delete('donations/{id}', 'deletePayment')->name('donations.delete');
                        Route::post('donations/{id}/status', 'updatePaymentStatus')->name('donations.status');
                    });

                    //Profile setting
                    Route::controller('ProfileController')->group(function () {
                        Route::get('profile-setting', 'profile')->name('profile.setting');
                        Route::post('profile-setting', 'submitProfile');
                        Route::get('change-password', 'changePassword')->name('change.password');
                        Route::post('change-password', 'submitPassword');
                    });

                    //E-pin Recharge
                    Route::controller('EpinController')->group(function () {
                        Route::get('/e-pin/recharge', 'epin')->name('epin.recharge');
                        Route::get('/e-pin/recharge/log', 'epinRechargeLog')->name('recharge.log');
                        Route::post('/e-recharge', 'eRecharge')->name('erecharge');
                        Route::post('/pin/generate', 'pinGenerate')->name('pin.generate');
                    });

                    // Withdraw
                    Route::controller('WithdrawController')
                        ->prefix('withdraw')
                        ->name('withdraw')
                        ->group(function () {
                            Route::get('/', 'withdrawMoney');
                            Route::post('/', 'withdrawStore')->name('.money');
                            Route::get('preview', 'withdrawPreview')->name('.preview');
                            Route::post('preview', 'withdrawSubmit')->name('.submit');

                            Route::get('history', 'withdrawLog')->name('.history');
                        });
                });

            // Payment
            Route::middleware('registration.complete')
                ->prefix('deposit')
                ->name('deposit.')
                ->controller('Gateway\PaymentController')
                ->group(function () {
                    Route::any('/', 'deposit')->name('index');
                    Route::post('insert', 'depositInsert')->name('insert');
                    Route::get('confirm', 'depositConfirm')->name('confirm');
                    Route::get('manual', 'manualDepositConfirm')->name('manual.confirm');
                    Route::post('manual', 'manualDepositUpdate')->name('manual.update');
                });

            //PlanController
            Route::post('/plan/purchase/{id}', 'PlanController@purchasePlan')->name('plan.purchase');
            Route::post('/plan/order/initiate', 'PlanController@initiate')->name('plan.initiate');
            Route::post('/plan/payment/status', 'PlanController@paymentStatus')->name('plan.success');
            Route::post('/subscribe/plan/order/{id}', 'PlanController@planOrder')->name('plan.order');
        });
    });
