<?php


use App\Http\Controllers\ClaimsController;
use App\Http\Controllers\CoversReportController;
use App\Http\Controllers\GroupController;
use App\Http\Controllers\KycDocumentController;
use App\Http\Controllers\SmsController;
use App\Http\Controllers\MemberController;
use App\Http\Controllers\MemberManagementController;
use App\Http\Controllers\MemberprofileController;
use App\Http\Controllers\OtpController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\PaymentProcessingController;
use App\Http\Controllers\PaymentReportController;
use App\Http\Controllers\SendSmsController;
use App\Http\Controllers\SettingsController;
use App\Http\Controllers\TrendsController;
use App\Http\Controllers\WhatsAppController;
use Illuminate\Support\Facades\Artisan;
use App\Http\Controllers\UserController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', 'App\Http\Controllers\AdminController@index')->middleware(['auth', 'verified'])->name('dashboard');
Route::get('/dashboard', 'App\Http\Controllers\AdminController@index')->middleware(['auth', 'verified'])->name('dashboard');


//Route::get('/reports/covers/popular', [CoversReportController::class, 'popularCoverStructures']);





Route::middleware('auth')->group(function () {
    
      Route::get('/deletedpayments', [PaymentController::class, 'alldeleted']);

    Route::get('/covers-report/popular', [CoversReportController::class, 'popularCoverStructures']);
Route::get('/covers-report/benefit-by-age', [CoversReportController::class, 'benefitPopularityByAgeGroup']);
Route::get('/covers-report/lapse-analysis', [CoversReportController::class, 'lapseAnalysisByCover']);
Route::get('/covers-report/new-vs-lapsed', [CoversReportController::class, 'newVsLapsedMembers']);
    
    Route::get('/trends/current-members-by-gender', [TrendsController::class, 'currentMembersByGender'])
        ->name('trends.current_members_by_gender');

    Route::get('/trends/members-by-age-group', [TrendsController::class, 'membersByAgeGroup'])
        ->name('trends.members_by_age_group');

    Route::get('/trends/membership-growth', [TrendsController::class, 'membershipGrowthTrends'])
        ->name('trends.membership_growth');

    Route::get('/trends/contribution-rates', [TrendsController::class, 'contributionRates'])
        ->name('trends.contribution_rates');

    Route::get('/trends/payment-patterns', [TrendsController::class, 'paymentPatterns'])
        ->name('trends.payment_patterns');

    Route::get('/settings', [SettingsController::class, 'index'])->name('settings.index');
    Route::post('/settings', [SettingsController::class, 'store'])->name('settings.store');

    // Claims Routes without "admin" prefix
    Route::get('claims', [ClaimsController::class, 'index'])->name('claims.index');
    Route::get('claims/pending', [ClaimsController::class, 'pending'])->name('claims.pending');
    Route::get('claims/approved', [ClaimsController::class, 'approved'])->name('claims.approved');
    Route::get('claims/rejected', [ClaimsController::class, 'rejected'])->name('claims.rejected');
    Route::get('claims/review', [ClaimsController::class, 'review'])->name('claims.review');

    Route::get('claim/{id}', [ClaimsController::class, 'show'])->name('claims.show');
    Route::get('claim/edit/{claim}', [ClaimsController::class, 'edit'])->name('claims.edit');
    Route::delete('claims/{claim}', [ClaimsController::class, 'destroy'])->name('claims.delete');
    Route::put('/claims/{claim}', [ClaimsController::class, 'updateInfo'])->name('claims.update');
    Route::get('claims/{claim}/print', [ClaimsController::class, 'print'])->name('claims.print');


    Route::get('member/{id}/claims', [ClaimsController::class, 'memberClaims'])->name('claims.member');


    // Claim Routes
    Route::get('claims/{claim}/edit', [ClaimsController::class, 'edit'])->name('claims.edit');
    //Route::post('claims/{claim}/update', [ClaimsController::class, 'update'])->name('claims.update');

    // Claim Documents
    Route::post('claims/{claim}/documents', [ClaimsController::class, 'uploadDocument'])->name('claims.documents.upload');
    Route::delete('claims/documents/{document}/delete', [ClaimsController::class, 'deleteDocument'])->name('claims.documents.delete');


    Route::get('/sms', [SmsController::class, 'index']);
    Route::get('/sms/{id}', [SmsController::class, 'view']);
    Route::post('/sms', [SmsController::class, 'search']);
    Route::post('/search_sms', [SmsController::class, 'searchSms']);

    Route::get('/admin/resend-failed-sms', [SendSmsController::class, 'resendFailedSms'])
        ->middleware('auth')
        ->name('admin.resend.failed.sms');



    // Member
    Route::get('/member', [MemberController::class, 'index']);
    // Government
    Route::get('/government', [MemberController::class, 'government']);

    // Refresh Status
    Route::get('/allstatus', [MemberprofileController::class, 'status']);

    //Members

    Route::get('/notify-member/{id}', [MemberManagementController::class, 'notify_member']);

    Route::prefix('kyc')->group(function () {
        Route::get('/{memberId}', [KycDocumentController::class, 'index'])->name('kyc.index');
        Route::get('/{memberId}/upload', [KycDocumentController::class, 'create'])->name('kyc.create');
        Route::post('/{memberId}/store', [KycDocumentController::class, 'store'])->name('kyc.store');
        Route::get('/view/{id}', [KycDocumentController::class, 'show'])->name('kyc.show');
        Route::post('/update-status/{id}', [KycDocumentController::class, 'updateStatus'])->name('kyc.updateStatus');
        Route::delete('/delete/{id}', [KycDocumentController::class, 'destroy'])->name('kyc.destroy');
    });

    Route::get('/send-whatsapp', function () {
        return view('whatsapp.send');
    });

    Route::post('/send-whatsapp', [WhatsAppController::class, 'sendMessage'])->name('whatsapp.send');

    Route::get('/allmembers', [MemberController::class, 'all']);
    Route::get('/findmember', [MemberController::class, 'find']);
    Route::get('/findMember/{national_id}', [MemberController::class, 'find_id']);
    Route::get('/card/{id}', [MemberController::class, 'card']);

    Route::post('/member', [MemberController::class, 'store']);
    Route::get('/member/{id}', [MemberController::class, 'view']);
    Route::put('/member/{id}', [MemberController::class, 'update']);
    Route::get('/member_profile/{id}', [MemberprofileController::class, 'index']);
    Route::get('/predelete_member/{id}', [MemberController::class, 'predelete']);
    Route::post('/delete_member', [MemberController::class, 'delete']);
    Route::post('/search_member', [MemberController::class, 'searchmember']);
    Route::post('/search_member1', [MemberController::class, 'searchmember1']);
    Route::post('/search_member2', [MemberController::class, 'searchmember2']);
    Route::get('/print_profile/{id}', [MemberController::class, 'print']);
    Route::get('/history/{id}', [MemberController::class, 'history']);


    Route::get('/restart/{id}', 'App\Http\Controllers\MemberController@restartView');
    Route::post('/restart', 'App\Http\Controllers\MemberController@restartMember');

    Route::get('/memberpermonth/{date}', 'App\Http\Controllers\MemberController@date');

    Route::get('/active', 'App\Http\Controllers\MemberController@active');
    Route::get('/pending', 'App\Http\Controllers\MemberController@pending');
    Route::get('/elapsed', 'App\Http\Controllers\MemberController@elapsed');
    Route::get('/restart', 'App\Http\Controllers\MemberController@restart');


    Route::post('/search_date_member', 'App\Http\Controllers\MemberController@searchdate');
    Route::post('/search_group_member', [App\Http\Controllers\MemberController::class, 'searchGroupMember']);


    // Group Routes
    Route::get('/group', [GroupController::class, 'index']);
    Route::get('/allgroups', [GroupController::class, 'all']);
    Route::post('/group', [GroupController::class, 'store']);
    Route::get('/group/{id}', [GroupController::class, 'view']);
    Route::put('/group/{id}', [GroupController::class, 'update']);
    Route::get('/delete_group/{id}', [GroupController::class, 'delete']);

    //user
    Route::get('/user', 'App\Http\Controllers\UserController@index');
    Route::get('/allusers', 'App\Http\Controllers\UserController@all');
    Route::post('/user', 'App\Http\Controllers\UserController@store');
    Route::get('/user/{id}', 'App\Http\Controllers\UserController@view');
    Route::put('/user/{id}', 'App\Http\Controllers\UserController@update');
    Route::get('/user_profile/{id}', 'App\Http\Controllers\UserController@profile');
    Route::get('/delete_user/{id}', 'App\Http\Controllers\UserController@delete');
    Route::post('/search_user', 'App\Http\Controllers\UserController@searchuser');

    Route::get('/userlog/{id}', 'App\Http\Controllers\UserController@log');
    
    Route::get('/user/status/{id}/{status}', [UserController::class, 'changeStatus']);

    Route::get('/agentprofile/{id}', 'App\Http\Controllers\UserController@profile');
    //Route::post('/agent_payment', 'App\Http\Controllers\UserController@payment');
    Route::post('/agent_monthcovered', 'App\Http\Controllers\UserController@monthcovered');
    //Route::post('/agent_stats', 'App\Http\Controllers\UserController@stats');




    Route::get('/personalinfo/{id}', 'App\Http\Controllers\UserController@personalinfo');
    Route::put('/personalinfo/{id}', 'App\Http\Controllers\UserController@profileupdate');
    Route::put('/passwordreset/{id}', 'App\Http\Controllers\UserController@password');


    //dependant
    Route::get('/new_dependant/{id}', 'App\Http\Controllers\DependantController@index');
    Route::get('/alldependants/{id}', 'App\Http\Controllers\DependantController@all');
    Route::post('/dependant', 'App\Http\Controllers\DependantController@store');
    Route::get('/dependant/{id}', 'App\Http\Controllers\DependantController@view');
    Route::put('/dependant/{id}', 'App\Http\Controllers\DependantController@update');
    Route::get('/delete_dependant/{id}', 'App\Http\Controllers\DependantController@delete');

    //Beneficiary
    Route::get('/new_beneficiary/{id}', 'App\Http\Controllers\BeneficiaryController@index');
    Route::get('/allbeneficiaries/{id}', 'App\Http\Controllers\BeneficiaryController@all');
    Route::post('/beneficiary', 'App\Http\Controllers\BeneficiaryController@store');
    Route::get('/beneficiary/{id}', 'App\Http\Controllers\BeneficiaryController@view');
    Route::put('/beneficiary/{id}', 'App\Http\Controllers\BeneficiaryController@update');
    Route::get('/delete_beneficiary/{id}', 'App\Http\Controllers\BeneficiaryController@delete');

    //Cover
    Route::get('/cover', 'App\Http\Controllers\CoverController@index');
    Route::get('/allcovers', 'App\Http\Controllers\CoverController@all');
    Route::post('/cover', 'App\Http\Controllers\CoverController@store');
    Route::get('/cover/{id}', 'App\Http\Controllers\CoverController@view');
    Route::put('/cover/{id}', 'App\Http\Controllers\CoverController@update');
    Route::get('/delete_cover/{id}', 'App\Http\Controllers\CoverController@delete');


    //Sponsor
    Route::get('/sponsor', 'App\Http\Controllers\SponsorController@index');
    Route::get('/allsponsors', 'App\Http\Controllers\SponsorController@all');
    Route::post('/sponsor', 'App\Http\Controllers\SponsorController@store');
    Route::get('/sponsor/{id}', 'App\Http\Controllers\SponsorController@view');
    Route::put('/sponsor/{id}', 'App\Http\Controllers\SponsorController@update');
    Route::get('/delete_sponsor/{id}', 'App\Http\Controllers\SponsorController@delete');

    //Premium
    Route::post('/premium', 'App\Http\Controllers\PremiumController@store');
    Route::get('/additional/{id}', 'App\Http\Controllers\PremiumController@additional');
    Route::post('/additional', 'App\Http\Controllers\PremiumController@benefit');
    Route::get('/memberonly/{id}', 'App\Http\Controllers\PremiumController@memberonly');
    Route::get('/memberspouse/{id}', 'App\Http\Controllers\PremiumController@memberspouse');
    //New amount
    // Route::get('/premium_new/{id}', 'App\Http\Controllers\PremiumController@newPremium');
    Route::get('/premium_new', 'App\Http\Controllers\PremiumController@newPremium');


    //Make Payment    
    // Route::post('/payment', [PaymentController::class, 'store']);

    
    Route::get('/user-payments-report', [PaymentReportController::class, 'showUserPaymentsForm']);
    Route::post('/user-payments-report', [PaymentReportController::class, 'generateUserPaymentsReport']);

    Route::get('/admin/payment-stats', [PaymentProcessingController::class, 'paymentStats'])
        ->middleware('auth')
        ->name('admin.payment.stats');


    //Route::post('/payment', [PaymentProcessingController::class, 'processPayment']);

    
    //Make Payment    
    Route::post('/payment', [PaymentController::class, 'store']);

    //
    Route::get('/new_payment/{id}', [PaymentController::class, 'index']);
    Route::get('/allpayments', [PaymentController::class, 'all']);
    Route::get('/allpaymentstodelete', [PaymentController::class, 'alltodelete']);
    Route::get('/memberpayments/{id}', [PaymentController::class, 'all1']);
    Route::get('/payment/{id}', [PaymentController::class, 'view']);
    Route::put('/payment/{id}', [PaymentController::class, 'update']);
    Route::get('/delete_payment/{id}/{member_id}', [PaymentController::class, 'delete']);
    Route::post('/search_payment', [PaymentController::class, 'search']);
    Route::post('/search_cover', [PaymentController::class, 'searchcover']);
    Route::post('/search_arrear', [PaymentController::class, 'searcharrear']);
    Route::get('/monthscovered', [PaymentController::class, 'monthscovered']);
    Route::get('/receipt/{id}', [PaymentController::class, 'receipt']);
    Route::put('/payment_edit/{id}', [PaymentController::class, 'edit_request']);
    Route::get('/payment_edit/{id}', [PaymentController::class, 'editView']);
    Route::get('/payment_preview/{id}', [PaymentController::class, 'preview']);




    //REPORTS
    Route::get('/paymentsreport', 'App\Http\Controllers\ReportController@payment');
    Route::get('/coversreport', 'App\Http\Controllers\ReportController@cover');


    Route::get('/arrearsreport', 'App\Http\Controllers\ReportController@arrear');
    Route::get('/arrears/{id}', 'App\Http\Controllers\ReportController@arrear1');
    Route::post('/search_cover_payment', 'App\Http\Controllers\ReportController@searchcover');
    Route::get('/statement/{id}', 'App\Http\Controllers\ReportController@statement');
    Route::post('/search_member_payment', 'App\Http\Controllers\ReportController@searchmember');
    Route::post('/search_date_payment', 'App\Http\Controllers\ReportController@searchdate');

    Route::post('/search_date_arrear', 'App\Http\Controllers\ReportController@searchdatearrear');
    Route::post('/search_date_cover', 'App\Http\Controllers\ReportController@searchdatecover');

    Route::post('/search_date_cover_all', 'App\Http\Controllers\ReportController@searchdatecoverall');
    Route::post('/search_date_payments_collected', 'App\Http\Controllers\ReportController@searchdatecoverall');


    Route::post('/search_date_payments_collected', 'App\Http\Controllers\ReportController@searchdatepaymentscollected');


    Route::post('/search_date_arrear_premia', 'App\Http\Controllers\ReportController@searchdatearrear_premia');
    Route::post('/search_date_cover_premia', 'App\Http\Controllers\ReportController@searchdatecover_premia');

    Route::get('/arrear_premia', 'App\Http\Controllers\ReportController@arrearpremia');
    Route::get('/cover_premia', 'App\Http\Controllers\ReportController@coverpremia');

    //Wrong payment
    Route::get('/wrongpayment', 'App\Http\Controllers\PaymentController@wrong');
    Route::get('/delete_wrongpayment/{id}', 'App\Http\Controllers\PaymentController@wrongdelete');


    //Notifications
    Route::get('maskAsRead', function () {
        auth()->user()->unreadNotifications->markAsRead();
        return redirect()->back();
    })->name('markRead');

    Route::get('notify', function () {
        return view('notifications');
    })->name('notifications');

    Route::get('/notify', 'App\Http\Controllers\NotificationController@index')->name('notifications');
    Route::post('/search_date_notification', 'App\Http\Controllers\NotificationController@searchdate');
});


Route::get('/clear', function () {
    Artisan::call('cache:clear');
    Artisan::call('config:clear');
    Artisan::call('config:cache');
    return "Clear!";
});



Route::get('/otp-verify', [OtpController::class, 'showVerifyForm'])->name('otp.verify');
Route::post('/otp-verify', [OtpController::class, 'verifyOtp'])->name('otp.verify.post');


require __DIR__ . '/auth.php';
