<?php

use App\Http\Controllers\API\AddBannerController;
use App\Http\Controllers\API\AdminController;
use App\Http\Controllers\API\Appoinment\AppointmentController;
use App\Http\Controllers\API\Appoinment\ServiceProviderController;
use App\Http\Controllers\API\CommonController;
use App\Http\Controllers\API\CommonProvider;
use App\Http\Controllers\API\CommonProviderSpeciality;
use App\Http\Controllers\API\CustomerProfile;
use App\Http\Controllers\API\DoctorProfileCOntroller;
use App\Http\Controllers\API\DoctorSpecialityController;
use App\Http\Controllers\API\DoctorTitle;
use App\Http\Controllers\API\DoctorType;
use App\Http\Controllers\API\Document\DocumentController;
use App\Http\Controllers\API\EarningController;
use App\Http\Controllers\API\LanguageStateController;
use App\Http\Controllers\API\LawyerProfileController;
use App\Http\Controllers\API\LawyerSpecialityController;
use App\Http\Controllers\API\LawyerTitleController;
use App\Http\Controllers\API\Review\ReviewController;
use App\Http\Controllers\API\RoleController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\API\OtpController;
use App\Http\Controllers\API\RegisterController;
use App\Http\Controllers\API\LoginController;
use App\Http\Controllers\API\ModeratorProfile;
use App\Http\Controllers\API\OrderController;
use App\Http\Controllers\API\PaymentRecordController;
use App\Http\Controllers\API\PromocodeController;
use App\Http\Controllers\API\ProviderController;
use App\Http\Controllers\API\ServiceProvider;
use App\Http\Controllers\API\SslCommerzController;
use App\Http\Controllers\API\StreamController;
use App\Http\Controllers\API\UnAuthenticatedController;
use App\Http\Controllers\ComplaintController;
use App\Models\Complaint;

use App\Models\User;
use App\Notifications\ProviderRegisteredNotification;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\Facades\Notification;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

Broadcast::routes(['middleware' => ['auth:sanctum']]);
// Broadcast::routes();

Route::middleware('auth:sanctum')->group(function () {

    Route::post('/refresh-token', [LoginController::class, 'refreshToken']);
    Route::get('/check-token', [LoginController::class, 'checkToken']);
});

Route::get('/test-ngrok', function (Request $request) {
    return response()->json(['message' => 'This is a test route for ngrok']);
});

Route::prefix('sslcommerz')->group(function () {


    Route::post('/success', [SslCommerzController::class, 'success'])->name('api.sslcommerz.success');
    Route::post('/fail', [SslCommerzController::class, 'fail'])->name('api.sslcommerz.fail');
    Route::post('/cancel', [SslCommerzController::class, 'cancel'])->name('api.sslcommerz.cancel');
    Route::post('/ipn', [SslCommerzController::class, 'ipn'])->name('api.sslcommerz.ipn');
});

Route::middleware(['auth:sanctum', 'check.token.expiration'])->group(function () {

    Route::prefix('sslcommerz')->group(function () {
        Route::post('/initiate-payment', [SslCommerzController::class, 'initiatePayment']);
        Route::post('/refund', [SslCommerzController::class, 'refund']);
        Route::post('/refundStatus', [SslCommerzController::class, 'refundStatus']);
    });


    //customer

    Route::middleware('customer')->group(function () {
        Route::put('/customer-update', [CustomerProfile::class, 'update']);
        Route::get('/customer-profile', [CustomerProfile::class, 'show']);
        Route::post('/check-password', [CustomerProfile::class, 'checkPassword']);

        Route::post('/profile/image', [CustomerProfile::class, 'addProfileImage']);
        Route::post('/update/profile/image', [CustomerProfile::class, 'updateProfileImage']);

        Route::post('/appointments', [AppointmentController::class, 'bookAppointment']);
        
        Route::get('/appointments/user/{uniqueUserId}', [AppointmentController::class, 'getAppointmentsByUser']);
        Route::get('/appointments/user/upcoming/{uniqueUserId}', [AppointmentController::class, 'upcomingAppointmentsForUser']);
        Route::get('/appointments/user/history/{uniqueUserId}', [AppointmentController::class, 'historyAppointmentsForUser']);


        Route::post('/complain-store', [ComplaintController::class, 'store']);
        Route::get('/user/provider/complain/{providerUniqueId}', [ComplaintController::class, 'getUserProviderComplaints']);






        Route::get('/cancel/appointments/{appointmentId}', [AppointmentController::class, 'cancelAppointmentWithinTime']);
        //Route::get('/check-availability/{provider_unique_user_id}/{appointment_date}', [AppointmentController::class, 'checkAvailability']);


       
        







        Route::get('/language-state', [LanguageStateController::class, 'getLanguageState']);
        Route::post('/language-state', [LanguageStateController::class, 'createOrUpdateLanguageState']);


        Route::get('/document/list-provider-members/{roleId}', [DocumentController::class, 'listProviderMembers']);
        Route::get('/providers/{providerUniqueId}/documents', [DocumentController::class, 'getDocumentsBetweenUsers']);
        Route::get('/documents/{documentId}/download', [DocumentController::class, 'downloadDocument']);
        Route::get('/documents/{providerId}/download-all', [DocumentController::class, 'downloadAllDocuments']);

        Route::post('/check-promocode', [PromocodeController::class, 'check']);
        
    });

    //moderator

    Route::middleware('moderator')->group(function () {
        Route::put('/moderator-update', [ModeratorProfile::class, 'update']);
        Route::get('/moderator-profile', [ModeratorProfile::class, 'show']);

        Route::post('/moderator/profile/image', [ModeratorProfile::class, 'addProfileImage']);
        Route::post('/update/moderator/profile/image', [ModeratorProfile::class, 'updateProfileImage']);
        

       
    });

    //common provider

    Route::middleware('commonprovider')->group(function () {
        Route::put('/common-provider-update', [CommonProvider::class, 'update']);
        Route::get('/common-provider-profile', [CommonProvider::class, 'show']);

        Route::post('/common-provider/profile/image', [CommonProvider::class, 'addProfileImage']);
        Route::put('/update/common-provider/profile/image', [CommonProvider::class, 'updateProfileImage']);

        // Update only pricing
        Route::put('/common-provider-profile/pricing', [CommonProvider::class, 'updatePricing']);

        // Update only availability status
        Route::put('/common-provider-profile/availability', [CommonProvider::class, 'updateAvailability']);
    });


    // all service provider

    Route::middleware('provider')->group(function () {
        Route::post('/providers/schedule', [ServiceProviderController::class, 'storeAvailability']);
        Route::put('/providers/schedule/{id}', [ServiceProviderController::class, 'updateAvailability']);
        Route::delete('/providers/schedule/{id}', [ServiceProviderController::class, 'deleteAvailability']);
        Route::get('/appointments/provider/{uniqueUserId}', [AppointmentController::class, 'getAppointmentsByProvider']);


        Route::get('/appointments/provider/upcoming/{uniqueUserId}', [AppointmentController::class, 'upcomingAppointmentsForProvider']);
        Route::get('/appointments/provider/history/{uniqueUserId}', [AppointmentController::class, 'historyAppointmentsForProvider']);
        // Route::delete('/appointments/{appointmentId}', [AppointmentController::class, 'deleteAppointment']);
        
        


        Route::post('/provider/withdraw-request', [EarningController::class, 'requestWithdrawal']);

        Route::get('/provider/earnings', [EarningController::class, 'getEarnings']);


        Route::get('/appointments/{date}', [AppointmentController::class, 'getAppointmentsByDate']);

        Route::get('/appointments/with-customer/{customerUniqueId}', [AppointmentController::class, 'appointmentsWithCustomer']);
        Route::get('/provider/appointments/overview', [AppointmentController::class, 'providerOverview']);
        Route::post('/appointments/{id}/cancel', [AppointmentController::class, 'cancelAppointmentByProvider']);

        
        
        

        Route::post('/complaints/provider', [ComplaintController::class, 'storeByProvider']);

        Route::post('/provider/appointments/{appointment}/conduct-status', [AppointmentController::class, 'updateConductStatus']);
        Route::post('/generate/prescription/{appointmentId}', [AppointmentController::class, 'generatePrescription']);
    });






    //super admin
    Route::middleware('superadmin')->group(function () {
        
       

        //for customer only
        Route::get('/customer/{uniqueUserId}', [AdminController::class, 'getUserWithProfile']);
        
        
        Route::put('/customer/{uniqueUserId}/deactivate', [AdminController::class, 'deactivateUser']);
        Route::get('/all-customer', [AdminController::class, 'getAllUsers']);


        
        Route::get('/moderator/{uniqueModeratorId}', [AdminController::class, 'getSingleModerator']);
        
        


        Route::get('/all-roles', [AdminController::class, 'getAllRoles']);
        Route::get('/role/{roleId}', [AdminController::class, 'getSingleRole']);
        
        


        Route::get('/doctor-types', [DoctorType::class, 'index']);
        Route::get('/doctor-types/{id}', [DoctorType::class, 'show']);
        Route::post('/doctor-types', [DoctorType::class, 'store']);
        Route::put('/doctor-types/{id}', [DoctorType::class, 'update']);
        Route::delete('/doctor-types/{id}', [DoctorType::class, 'destroy']);



        Route::get('/doctor-specialities', [DoctorSpecialityController::class, 'index']);
        Route::get('/doctor-specialities/{id}', [DoctorSpecialityController::class, 'show']);


        Route::get('/doctor-titles', [DoctorTitle::class, 'index']);
        Route::get('/doctor-titles/{id}', [DoctorTitle::class, 'show']);
        Route::post('/doctor-titles', [DoctorTitle::class, 'store']);
        Route::put('/doctor-titles/{id}', [DoctorTitle::class, 'update']);
        Route::delete('/doctor-titles/{id}', [DoctorTitle::class, 'destroy']);

        Route::get('/lawyer-titles', [LawyerTitleController::class, 'index']);
        Route::get('/lawyer-titles/{id}', [LawyerTitleController::class, 'show']);
        Route::post('/lawyer-titles', [LawyerTitleController::class, 'store']);
        Route::put('/lawyer-titles/{id}', [LawyerTitleController::class, 'update']);
        Route::delete('/lawyer-titles/{id}', [LawyerTitleController::class, 'destroy']);


        Route::get('/lawyer-specialities', [LawyerSpecialityController::class, 'index']);
        Route::get('/lawyer-specialities/{id}', [LawyerSpecialityController::class, 'show']);
        Route::post('/lawyer-specialities', [LawyerSpecialityController::class, 'store']);
        Route::post('/update/lawyer-specialities/{id}', [LawyerSpecialityController::class, 'update']);
        Route::delete('/lawyer-specialities/{id}', [LawyerSpecialityController::class, 'destroy']);



        Route::post('/create-service-provider', [AdminController::class, 'createServiceProviderRole']);

        




        //common provider speciality
       

        Route::get('/common-provider-specialities/{id}', [CommonProviderSpeciality::class, 'getCommonProviderSpecialityById']);
        



        Route::delete('/appointments/{appointmentId}', [AppointmentController::class, 'deleteAppointment']);

        //ADD BANNER

       

        
        

        
    });


    //Doctor
    Route::middleware('doctor')->group(function () {
        Route::put('/doctor-update', [DoctorProfileCOntroller::class, 'update']);
        Route::get('/doctor-profile', [DoctorProfileCOntroller::class, 'show']);

        Route::post('/doctor/profile/image', [DoctorProfileCOntroller::class, 'addProfileImage']);
        Route::put('/update/doctor/profile/image', [DoctorProfileCOntroller::class, 'updateProfileImage']);

        // Update only pricing
        Route::put('/doctor-profile/pricing', [DoctorProfileController::class, 'updatePricing']);

        // Update only availability status
        Route::put('/doctor-profile/availability', [DoctorProfileController::class, 'updateAvailability']);
    });

    // Lawyer
    Route::middleware('lawyer')->group(function () {
        Route::put('/lawyer-update', [LawyerProfileController::class, 'update']);
        Route::get('/lawyer-profile', [LawyerProfileController::class, 'show']);

        Route::post('/lawyer/profile/image', [LawyerProfileController::class, 'addProfileImage']);
        Route::put('/update/lawyer/profile/image', [LawyerProfileController::class, 'updateProfileImage']);

        // Update only pricing
        Route::put('/lawyer-profile/pricing', [LawyerProfileController::class, 'updatePricing']);

        // Update only availability status
        Route::put('/lawyer-profile/availability', [LawyerProfileController::class, 'updateAvailability']);
    });

    Route::middleware(['author:super admin,moderator'])->group(function () {
        Route::post('/promocodes', [PromocodeController::class, 'store']);
        Route::post('/promocodes/store-assign', [PromocodeController::class, 'storeAndAssign']);
        Route::get('/promocodes/{id}', [PromocodeController::class, 'show']);
        Route::put('/promocodes/{id}', [PromocodeController::class, 'update']);
        Route::put('/promocodes/status/{id}', [PromocodeController::class, 'statusUpdate']);
        Route::delete('/promocodes/{id}', [PromocodeController::class, 'destroy']);
        Route::post('/promocodes/assign', [PromocodeController::class, 'assign']);
        Route::get('/promocodes', [PromocodeController::class, 'getAllPromocodes']);
    });

    
    Route::middleware(['commonrole:super admin,moderator'])->group(function () {
        Route::put('/withdraw-status-update/{id}', [EarningController::class, 'updateStatus']);
        Route::get('/user-count', [CommonController::class, 'UserCount']);
        Route::get('/appointment-status-count', [AppointmentController::class, 'AppointmentStatusCount']);
        Route::get('/service-and-sub-service-count', [CommonController::class, 'serviceAndSubServiceCount']);
        Route::get('/revenue-profit-series', [CommonController::class, 'revenueProfitSeries']);
        Route::get('/getters-providers-series', [CommonController::class, 'gettersProvidersSeries']);
        //approve status
        Route::put('/approve-provider/{uniqueUserId}', [AdminController::class, 'approveProvider']);
        Route::get('/approve-requests', [CommonController::class, 'getPendingApprovalProviders']);
        Route::get('/all-providers', [CommonController::class, 'getAllProviders']);
        Route::get('/provider-revenue-board', [CommonController::class, 'providerRevenueBoard']);
        Route::put('/change-complaint-status/{complaintId}', [ComplaintController::class, 'changeComplaintStatus']);
        Route::delete('delete-provider/{uniqueUserId}', [CommonController::class, 'deleteProvider']);
        Route::get('/all/complain', [ComplaintController::class, 'getAllComplaints']);
        Route::get('/all-roles-for-promocode', [PromocodeController::class, 'getAllRoles']);
        Route::get('/all-user', [CommonController::class, 'getAllUsers']);
        Route::get('/provider-roles-specialities', [CommonController::class, 'getProviderRolesWithSpecialities']);
        Route::get('/all-getters', [CommonController::class, 'getAllCustomer']);
        Route::delete('/customer/{uniqueUserId}', [AdminController::class, 'deleteUser']);
        Route::put('/customer/{uniqueUserId}', [AdminController::class, 'updateUser']);
        Route::post('/create-moderator', [AdminController::class, 'create_moderator']);
        Route::get('/all-moderators', [AdminController::class, 'getAllModerators']);
        Route::delete('/delete-moderator/{uniqueModeratorId}', [AdminController::class, 'deleteModerator']);
        Route::put('/update-moderator/{uniqueModeratorId}', [AdminController::class, 'updateModerator']);
        Route::get('/provider-roles', [CommonController::class, 'getProviderRoles']);
        Route::put('/update/doctor/{uniqueUserId}', [CommonController::class, 'doctorUpdate']);
        Route::put('/update/lawyer/{uniqueUserId}', [CommonController::class, 'lawyerUpdate']);
        Route::put('/update/common/{uniqueUserId}', [CommonController::class, 'commonUpdate']);
        Route::get('/provider-categories', [ServiceProvider::class, 'categories']);
        Route::get('/provider-subcategories', [ServiceProvider::class, 'subcategories']);
        Route::post('/create-roles', [RoleController::class, 'createRole']);
        Route::post('/update-role/{roleId}', [AdminController::class, 'updateRole']);
        Route::delete('/delete-role/{roleId}', [AdminController::class, 'deleteRole']);

        Route::post('/doctor-specialities', [DoctorSpecialityController::class, 'store']);
        Route::post('/update/doctor-specialities/{id}', [DoctorSpecialityController::class, 'update']);
        Route::delete('/doctor-specialities/{id}', [DoctorSpecialityController::class, 'destroy']);

        Route::post('/lawyer-specialities', [LawyerSpecialityController::class, 'store']);
        Route::post('/update/lawyer-specialities/{id}', [LawyerSpecialityController::class, 'update']);
        Route::delete('/lawyer-specialities/{id}', [LawyerSpecialityController::class, 'destroy']);

        Route::post('/create-common-provider-speciality', [CommonProviderSpeciality::class, 'addCommonProviderSpeciality']);
        Route::post('/update/common-provider-specialities/{id}', [CommonProviderSpeciality::class, 'updateCommonProviderSpeciality']);
        Route::delete('/common-provider-specialities/{id}', [CommonProviderSpeciality::class, 'deleteCommonProviderSpeciality']);
        Route::post('/payment-records', [PaymentRecordController::class, 'store']);
        Route::get('/payment-records/last/{user}', [PaymentRecordController::class, 'lastByUser']);
        Route::get('/providers/payment-summary', [PaymentRecordController::class, 'providersPaymentSummary']);
        Route::put('/payment-records/{paymentRecord}', [PaymentRecordController::class, 'update']);
        Route::get('/banner/all', [AddBannerController::class, 'getAll']);
        Route::post('/banner/store', [AddBannerController::class, 'store']);  // Store a new banner
        Route::delete('/banner/delete/{id}', [AddBannerController::class, 'delete']);  // Delete a banner


        // For role wised add banner 
        Route::post('/role/banner/store/{roleId}', [AddBannerController::class, 'storeByRole']);  // Store a new banner
    });

    
    Route::middleware(['commonrole:super admin,moderator,provider'])->group(function () {
        Route::put('/appointments/status/{appointmentId}', [AppointmentController::class, 'updateAppointmentStatus']);
    });

    Route::middleware(['commonrole:customer,provider'])->group(function () {
        Route::post('/appointments/{id}/reschedule', [AppointmentController::class, 'rescheduleAppointment']);
        Route::put('/appointments/{appointmentId}', [AppointmentController::class, 'updateAppointment']);
        Route::post('/phone/change/otp/send', [OtpController::class, 'sendOtpForPhoneChange']);
        Route::post('/otp/verify/update/phone', [OtpController::class, 'verifyOtpAndChangePhone']);
        Route::get('/check-availability/{provider_unique_user_id}/{appointment_date}', [AppointmentController::class, 'checkAvailability']);
        
    });

    


    // Documents
    Route::post('/document/upload', [DocumentController::class, 'upload']);

    Route::post('/document/upload-multiple', [DocumentController::class, 'uploadMultiple']);

    Route::get('/document/user/{uniqueId}', [DocumentController::class, 'getVerificationDocuments']);
    Route::get('/document/user/{uniqueId}/public', [DocumentController::class, 'getPublicDocuments']);
    Route::get('/document/appointment/{id}', [DocumentController::class, 'getDocumentsByAppointment']);
    Route::get('/document/private/customer/{customerUniqueId}/provider/{providerUniqueId}', [DocumentController::class, 'getPrivateDocumentsForCustomer']);
    Route::get('/document/private/provider/{providerUniqueId}/customer/{customerUniqueId}', [DocumentController::class, 'getPrivateDocumentsForProvider']);
    Route::get('/document/private/provider', [DocumentController::class, 'getPrivateDocuments']);

    // Review   
    Route::post('/reviews', [ReviewController::class, 'store']);
    Route::put('/reviews/{id}/status', [ReviewController::class, 'updateStatus']);
    Route::get('/service-providers/{serviceProviderUniqueId}/reviews', [ReviewController::class, 'getApprovedReviews']);


    //

    // Common Provider Speciality
    Route::get('/common-provider-specialities/{roleId}', [CommonProviderSpeciality::class, 'getCommonProviderSpecialitiesByRoleId']);



    Route::get('/providers/search', [ProviderController::class, 'search']);




    Route::get('/switch-user', [ServiceProvider::class, 'switchUser']);
    // Route::get('/service-providers-list/{specialityId}/{roleId}', [ServiceProvider::class, 'serviceProviderListBySpeciality']);

    Route::post('update-password', [LoginController::class, 'updatePassword']);



    Route::get('complain/provider/{providerUniqueId}', [ComplaintController::class, 'getComplaintsForProvider']);
    Route::get('/appointments/{appointment_id}/complaints', [ComplaintController::class, 'getComplaintsForAppointmentByCustomer']);

    Route::get('/order/history/{userUniqueId}', [OrderController::class, 'history']);


    Route::get('/all/withdraw-requests', [EarningController::class, 'getAllWithdrawRequests']);

    Route::get('/complaints/{appointmentId}', [ComplaintController::class, 'getComplaintForAppointmentByProvider']);



    // 1) Signed-in user gets a Stream user token
    Route::post('/stream/token', [StreamController::class, 'issueUserToken']);

    // 2) Upsert one or more users into Stream (used internally; can be admin-only if you prefer)
    Route::post('/stream/users/upsert', [StreamController::class, 'upsertUsers']);

    // 3) Doctor-only: start a call for a confirmed & upcoming appointment they own
    Route::post('/stream/calls/{appointmentId}/start', [StreamController::class, 'startCall']);
});

Route::post('/otp/send', [OtpController::class, 'sendOtp']);
Route::post('/otp/verify', [OtpController::class, 'verifyOtp']);

Route::post('/register', [RegisterController::class, 'register']);
Route::post('/login', [LoginController::class, 'login']);

Route::get('/all-roles-service-provider-customer', [UnAuthenticatedController::class, 'getAllRolesOfServiceProviderAndCustomer']);
Route::get('/all-roles-service-doctor-customer', [UnAuthenticatedController::class, 'getAllRolesOfServiceProviderAndCustomer']);
Route::get('/get-identification-placeholder/{roleId}', [UnAuthenticatedController::class, 'getIdentificationPlaceholder']);

Route::put('/reset-password', [UnAuthenticatedController::class, 'resetPassword']);

Route::post('/otp/resend', [OtpController::class, 'resendOtp']);



Route::get('/all-service-provider', [ServiceProvider::class, 'getServiceProvider']);
Route::get('/service-provider-speciality/{roleId}', [ServiceProvider::class, 'serviceProviderSpeciality']);
Route::get('/service-providers-list/{specialityId}/{roleId}', [ServiceProvider::class, 'serviceProviderListBySpeciality']);


Route::post('/forget-password/otp/send', [OtpController::class, 'sendOtpForForgetPassword']);
Route::post('/forget-password/otp/verify', [OtpController::class, 'verifyOtpForForgetPassword']);
Route::post('/forget-password/update', [OtpController::class, 'updatePasswordAfterForget']);
Route::get('banner/latest', [AddBannerController::class, 'getLatest']);  // Get the latest banner


Route::get('role/banner/latest/{roleId}', [AddBannerController::class, 'getLatestByRole']);  // Get the latest banner
Route::get('role/banner/all/{roleId}', [AddBannerController::class, 'getAllByRole']);  // Get all banners




Route::get('/send-public-notification', action: [AdminController::class, 'sendNotification']);
Route::middleware('auth:sanctum')->get('/send-private-notification', [AdminController::class, 'sendPrivateNotification']);
Route::get('/send-test-notification', function () {
    $admins = User::whereHas('role', function ($query) {
        $query->whereIn('name', ['super admin', 'moderator']);
    })->get();

    $user= User::find(26); // Get the user you want to notify

    // foreach ($admins as $admin) {
    //     $admin->notify(new ProviderRegisteredNotification($user, $admin));
    // }
    // Notification::send($admins, new ProviderRegisteredNotification($user));

    foreach ($admins as $admin) {
        $admin->notify(new ProviderRegisteredNotification($user, $admin));
    }

    return response()->json(['message' => 'Notifications sent to admins.']);
});

Route::middleware('auth:sanctum')->get('/notifications', function (Request $request) {
   $notifications = $request->user()->notifications;
    $unreadProviderNotifications = $request->user()->unreadNotifications;
    $readProviderNotifications = $request->user()->readNotifications;
   return response()->json([
       'all' => $notifications,
       'unread' => $unreadProviderNotifications,
       'read' => $readProviderNotifications
   ]);
});

Route::middleware('auth:sanctum')->get('/notifications/{id}', function (Request $request, $id) {
    $notification = $request->user()->notifications()->find($id);
    if ($notification) {
        $notification->markAsRead();
    }

    return response()->json(['message' => 'Notification marked as read', 'notification' => $notification]);
});

use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Support\Facades\File;

Route::get('/test-pdf', function () {


    $pdf = Pdf::loadView('prescription');

    $fileName = 'prescription.pdf';
    $filePath = public_path('pdf/' . $fileName);

    // Ensure the directory exists
    File::ensureDirectoryExists(public_path('pdf'));

    // Save the file to the public/pdf directory
    $pdf->save($filePath);

    return response()->json([
        'message' => 'PDF saved successfully',
        'url' => asset('pdf/' . $fileName)
    ]);
});