<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\AgentController;
use App\Http\Controllers\ManagerController;
use App\Http\Controllers\PatientController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\LeadController;
use App\Http\Controllers\DataController;
use App\Http\Controllers\CallLogController;
use App\Http\Controllers\UserApiController;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\PatientJourneyController;
use App\Http\Controllers\patientPassportController;


Route::post('login', [LoginController::class, 'login']);
Route::get('/leads', [LeadController::class, 'getAllFacebookLead']);
Route::post('/leads', [LeadController::class, 'createLead']);
Route::post('/webhook', [LeadController::class, 'webhook']);
#Route::post('/webhookPost', [LeadController::class, 'webhookPost']);
Route::post('/websiteLeadsStore', [LeadController::class, 'websiteData']);
Route::get('/websiteLeadsList', [LeadController::class, 'websiteDataList']);

Route::get('/getwhatsaapdata/{number}', [DataController::class, 'getWhatsappMsgId']);
Route::get('/allmessage', [DataController::class, 'getWhatsapp']);
Route::get('/callLog', [CallLogController::class, 'GetCallLog']);

Route::get('/webhook', function (Request $request) {
    $mode = $request->query('hub_mode');
    $token = $request->query('hub_verify_token');
    $challenge = $request->query('hub_challenge');
    
    if ($mode && $token) {
        if ($mode === 'subscribe' && $token === 'kbjhdsaufgvvhascdhf') {
            Log::info('Webhook verification Successfully.');
            return response($challenge, 200);
        } else {
             Log::warning('Webhook verification failed.');
            return response('', 403);
        }
    }
});

  Route::group(['middleware' => ['cors']], function () {
    Route::get('/', [HomeController::class, 'index'])->name('index');
    Route::get('/create', [HomeController::class, 'create'])->name('create');  
    Route::post('/create_post', [UserApiController::class, 'createPost']);
    Route::post('/profile', [HomeController::class, 'Profile'])->name('superadmin_profile');
    Route::post('/updateProfile', [HomeController::class, 'updateProfile'])->name('update');  
    Route::get('/role', function(){ $roledata= Role::get(); return view('role')->with(['roledata'=>$roledata]);});  
    Route::post('/addRole', [HomeController::class, 'addRole'])->name('add_role');
    Route::get('/delete/{id}', [HomeController::class, 'delete'])->name('delete');  
    Route::get('/userdelete/{id}', [HomeController::class, 'Userdelete'])->name('user_delete'); 
    Route::get('/smLeads', [LeadController::class, 'SocialMediaLeads'])->name('smLeads');
    Route::get('/waLeads', [LeadController::class, 'WhatsaapLeads'])->name('waLeads');
    Route::post('/webhookWhatsapp', [DataController::class, 'receiveData']);
    Route::get('/roleList', [RoleController::class, 'roleList']); 
    Route::post('/insertMedflick', [LeadController::class, 'SMMedflickDataPost']);
    Route::post('/postWebsiteDataMedflick', [LeadController::class, 'postDataMedflick']);
    Route::get('/getagent', [UserApiController::class, 'agentLsit']);
    Route::post('/useridleadid/{user_id}/{id}', [PatientJourneyController::class, 'getpatientagentId']);
    Route::get('/getleadsbyagentid/{user_id}', [PatientJourneyController::class, 'getLeadsbyUserId']);
    Route::get('/getLeaddetails/{lead_id}', [PatientJourneyController::class, 'getLeadDetails']);
    Route::post('/patientReportUpload', [PatientJourneyController::class, 'UploadPatientReportUpload']);
    Route::get('/reportDelete/{report_id}', [PatientJourneyController::class, 'patientReportDelete']);
    Route::post('/assignSpecialityPatient', [PatientJourneyController::class, 'assignSpecialityPatient']);
    Route::post('/patienthealthissue', [PatientJourneyController::class, 'patientHealthIssue']);
    Route::get('/getConversationList/{patient_id}/{user_id}/{patient_journey_id}', [PatientJourneyController::class, 'getConversation']);
    Route::post('/uploadpassport',[patientPassportController::class, 'uploadPassport']);
});