<?php

use App\Http\Controllers\api\v1\UsersController;
use App\Http\Controllers\api\v1\AdsController;
use App\Http\Controllers\api\v1\AuthController;
use App\Http\Controllers\api\v1\CategoryController;
use App\Http\Controllers\api\v1\HomeController;
use App\Http\Controllers\api\v1\GeneralController;
use App\Http\Controllers\api\v1\NotificationController;
use App\Http\Controllers\api\v1\PaymentController;
use App\Http\Controllers\api\v1\SearchController;
use App\Http\Controllers\api\v1\UserConnectionRequestController;
use App\Http\Controllers\api\v1\ChatController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::get('/user', function (Request $request) {
  return $request->user();
})->middleware('auth:sanctum');

Route::prefix('v1/auth')->middleware('lang_convert')->name('auth.')->group(function () {
  Route::post("check_sign_up", [AuthController::class, 'check_signup']);
  Route::post("sign_up", [AuthController::class, 'sign_up']);
  Route::post('get_sumsub_token', [AuthController::class, 'getSumsubToken']);

  Route::post('get_applicant_details', [AuthController::class, 'getApplicantDetails']);
  Route::post('get_applicant_detail_by_externaluserid', [AuthController::class, 'getApplicantDetailsByExternalUserId']);
  Route::post('create_applicant', [AuthController::class, 'createApplicant']);

  Route::post('resend_code', [AuthController::class, 'resend_code'])->name('resend_code');
  Route::post("verify_otp", [AuthController::class, 'verify_otp']);
  Route::post("email_login", [AuthController::class, 'email_login']);
  Route::post("social_login", [AuthController::class, 'social_login']);
  Route::post('resend_phone_code', [AuthController::class, 'resend_phone_code'])->name('resend_phone_code');
  Route::post("confirm_code", [AuthController::class, 'confirm_code']);
  Route::post('/forgot_password', [AuthController::class, 'forgot_password'])->name('forgot_password');
  Route::post('/reset_password_otp_verify', [AuthController::class, 'reset_password_otp_verify'])->name('user.reset_password_otp_verify');
  Route::post('/reset_password', [AuthController::class, 'reset_password'])->name('user.reset_password');
  Route::post('/resend_forgot_password_otp', [AuthController::class, 'resend_forgot_password_otp'])->name('user.resend_forgot_password_otp');
  Route::post("logout", [AuthController::class, 'logout']);
  Route::post("delete_account", [AuthController::class, 'delete_account']);
});

Route::prefix('v1')->middleware('lang_convert')->name('api.')->group(function () {
  //category routes
  Route::get('get_parent_category_list', [CategoryController::class, 'getParentCategoryList'])->name('get_parent_category_list');
  Route::get('get_sub_category_list', [CategoryController::class, 'getSubCategoryList'])->name('get_sub_category_list');

  //home routes
  Route::post('get_home_element_listing', [HomeController::class, 'getHomeElementListing'])->name('get_home_element_listing');
  Route::post('get_home_element_data', [HomeController::class, 'getElementDataById'])->name('get_home_element_data');

  //payment routes
  Route::post('user_plans', [PaymentController::class, 'userPlans'])->name('user_plans');
  Route::post('upgrade_plans', [PaymentController::class, 'upgradePlans'])->name('upgrade_plans');
  Route::post('checkout', [PaymentController::class, 'checkout'])->name('checkout');
  Route::post('payment_init', [PaymentController::class, 'paymentInit'])->name('payment_init');
  Route::post('payment_success', [PaymentController::class, 'paymentSuccess'])->name('payment_success');


  //user routes
  Route::post('/my_profile', [UsersController::class, 'my_profile'])->name('my_profile');
  Route::post('/get_minimal_user_profile', [UsersController::class, 'get_minimal_user_profile'])->name('get_minimal_user_profile');
  Route::post('/get_user_profile', [UsersController::class, 'get_user_profile'])->name('get_user_profile');
  Route::post('/update_user_profile', [UsersController::class, 'update_user_profile']);
  Route::post('/update_user_device_token', [UsersController::class, 'update_user_device_token']);
  Route::post('/validate_otp_phone_email_update', [UsersController::class, 'validate_otp_phone_email_update']);
  Route::post('/change_password', [UsersController::class, 'change_password']);
  Route::post('/update_notification_setting', [UsersController::class, 'update_notification_setting']);
  Route::post('/update_user_preference', [UsersController::class, 'update_user_preference']);
  Route::post('/get_user_preference', [UsersController::class, 'get_user_preference']);

  //support routes
  Route::post('create_support_ticket', [UsersController::class, 'create_support_ticket'])->name('create_support_ticket');
  Route::post('get_my_support_tickets', [UsersController::class, 'get_my_support_tickets'])->name('get_my_support_tickets');

  //master api 
  Route::post('get_chat_category_list', [GeneralController::class, 'getChatCategoryList']);
  Route::post('get_questions', [GeneralController::class, 'getChatQuestionList']);
  Route::post('get_answers', [GeneralController::class, 'getAnswerList']);
  Route::get('profile_step_1', [GeneralController::class, 'step1']);
  Route::get('profile_step_3', [GeneralController::class, 'step3']);
  Route::get('profile_step_5', [GeneralController::class, 'step5']);
  Route::get('profile_step_6', [GeneralController::class, 'step6']);
  Route::get('profile_step_8', [GeneralController::class, 'step8']);
  Route::get('get_general_list', [GeneralController::class, 'getGeneralList']);
  Route::get('get_nationalities_list', [GeneralController::class, 'getNationalitiesList']);
  Route::get('get_countries_list', [GeneralController::class, 'getCountriesList']);
  Route::get('get_activities_list', [GeneralController::class, 'getActivitiesList']);
  Route::get('get_marital_status_list', [GeneralController::class, 'getMaritalStatusList']);
  Route::get('get_sports_list', [GeneralController::class, 'getSportsList']);
  Route::get('get_employments_list', [GeneralController::class, 'getEmploymentsList']);
  Route::get('get_languages_list', [GeneralController::class, 'getLanguagesList']);
  Route::get('get_educations_list', [GeneralController::class, 'getEducationsList']);
  Route::get('get_professions_list', [GeneralController::class, 'getProfessionsList']);
  Route::get('get_dress_codes_list', [GeneralController::class, 'getDressCodesList']);
  Route::get('get_emirates_list', [GeneralController::class, 'getEmiratesList']);
  Route::get('get_sects_list', [GeneralController::class, 'getSectsList']);
  Route::get('get_diseases_list', [GeneralController::class, 'getDiseasesList']);
  Route::get('get_disease_variant_list', [GeneralController::class, 'getDiseaseVariantsList']);
  Route::get('get_report_types', [GeneralController::class, 'getReportTypeList'])->name('get_report_types');
  Route::get('get_chronic_diseases_list', [GeneralController::class, 'getCronicDiseasesList']);

  //home listing endpoints
  Route::post('get_user_match_listing', [HomeController::class, 'getUserMatchListing'])->name('get_user_match_listing');
  Route::post('get_premium_user_listing', [HomeController::class, 'getPremiumUserListing'])->name('get_premium_user_listing');
  Route::post('get_user_stats', [HomeController::class, 'getUserHomeStats'])->name('get_user_stats');
  Route::post('get_user_stats_listing', [HomeController::class, 'getStatUserList'])->name('get_user_stats_listing');


  //profile create api
  Route::post('delete_user_image', [UsersController::class, 'deleteUserImage'])->name('delete_user_image');
  Route::post('send_connection_request', [UserConnectionRequestController::class, 'send_connection_request']);
  Route::post('get_connection_request_list', [UserConnectionRequestController::class, 'get_connection_request_list']);
  Route::post('accept_connection_request', [UserConnectionRequestController::class, 'accept_connection_request']);
  Route::post('reject_connection_request', [UserConnectionRequestController::class, 'reject_connection_request']);
  Route::post('update_connection_status', [UserConnectionRequestController::class, 'update_connection_status']);

  Route::post('request_profile_picture', [\App\Http\Controllers\api\v1\ProfilePictureRequestController::class, 'requestProfilePicture']);
  Route::post('accept_profile_picture_request', [\App\Http\Controllers\api\v1\ProfilePictureRequestController::class, 'acceptProfilePictureRequest']);
  Route::post('reject_profile_picture_request', [\App\Http\Controllers\api\v1\ProfilePictureRequestController::class, 'rejectProfilePictureRequest']);

  Route::post('search', [SearchController::class, 'search']);
  Route::get('get-page-content', [GeneralController::class, 'getPageContent']);



  //notifcation routes
  Route::post('send_push_notification', [NotificationController::class, 'setPushNotification'])->name('send_push_notification');

  // Chat Module Routes
  Route::post('chat/initialize', [ChatController::class, 'initializeChat'])->name('chat.initialize');
  Route::get('chat/categories', [ChatController::class, 'getQuestionCategories'])->name('chat.categories');
  Route::post('chat/questions', [ChatController::class, 'getQuestionsByCategory'])->name('chat.questions');
  Route::post('chat/send-question', [ChatController::class, 'sendQuestion'])->name('chat.send_question');
  Route::post('chat/send-answer', [ChatController::class, 'sendAnswer'])->name('chat.send_answer');
  Route::post('chat/messages', [ChatController::class, 'getChatMessages'])->name('chat.messages');
  Route::post('chat/submit-decision', [ChatController::class, 'submitDecision'])->name('chat.submit_decision');
  Route::post('chat/user-chats', [ChatController::class, 'getUserChats'])->name('chat.user_chats');
  Route::post('chat/stats', [ChatController::class, 'getChatStats'])->name('chat.stats');

  // Cron job routes (should be protected with middleware in production)
  Route::post('chat/send-reminders', [ChatController::class, 'sendDecisionReminders'])->name('chat.send_reminders');
  Route::post('chat/auto-disconnect', [ChatController::class, 'autoDisconnectExpiredChats'])->name('chat.auto_disconnect');

});
