<?php

use CodeIgniter\Router\RouteCollection;

/** @var RouteCollection $routes */
$routes->get('/', 'Home::index');
$routes->get('/login', 'Auth::login');
$routes->post('/login', 'Auth::login');
$routes->get('/register', 'Auth::register');
$routes->post('/register', 'Auth::register');
$routes->get('/logout', 'Auth::logout');

$routes->group('admin', ['filter' => 'admin'], function ($routes) {
    $routes->get('/', 'Admin::dashboard');
    $routes->match(['GET', 'POST'], 'categories', 'Admin::categories');
    $routes->post('categories/update/(:num)', 'Admin::updateCategory/$1');
    $routes->get('categories/delete/(:num)', 'Admin::deleteCategory/$1');
    $routes->match(['GET', 'POST'], 'documents', 'Admin::documents');
    $routes->get('documents/upload', 'Admin::uploadDocument');
    $routes->post('documents/store', 'Admin::storeDocument');
    $routes->get('documents/train/(:num)', 'Admin::trainDocument/$1');
    $routes->get('documents/train-all', 'Admin::trainAllPending');
    $routes->get('documents/delete/(:num)', 'Admin::deleteDocument/$1');
    $routes->get('documents/visibility/(:num)/(:alpha)', 'Admin::toggleVisibility/$1/$2');
    $routes->match(['GET', 'POST'], 'chatbot-config', 'Admin::chatbotConfig');
    $routes->post('chatbot/test-connection', 'Admin::testOpenai');
    $routes->match(['GET', 'POST'], 'cloudtalk-settings', 'Admin::cloudtalkSettings');
    $routes->post('cloudtalk/test-connection', 'Admin::cloudtalkTestConnection');
    $routes->match(['GET', 'POST'], 'leads', 'Admin::leads');
    $routes->get('leads/create', 'Admin::createLead');
    $routes->post('leads/store', 'Admin::storeLead');
    $routes->get('leads/view/(:num)', 'Admin::viewLead/$1');
    $routes->get('leads/edit/(:num)', 'Admin::editLead/$1');
    $routes->post('leads/update/(:num)', 'Admin::updateLead/$1');
    $routes->get('leads/delete/(:num)', 'Admin::deleteLead/$1');
    $routes->post('leads/note/add/(:num)', 'Admin::addLeadNote/$1');
    $routes->post('leads/status/(:num)', 'Admin::leadUpdateStatus/$1');
    $routes->match(['GET', 'POST'], 'leads/sync-calls/(:num)', 'Admin::syncLeadCalls/$1');
    $routes->match(['GET', 'POST'], 'leads/book/(:num)', 'Admin::leadBook/$1');
    $routes->post('bookings/slots/(:num)', 'Admin::bookingSlotsAJAX/$1');
    $routes->post('bookings/slots', 'Admin::bookingSlotsAJAX');
    $routes->post('booking-slots/(:num)', 'Admin::bookingSlotsAJAX/$1');
    $routes->post('booking-slots', 'Admin::bookingSlotsAJAX');
    $routes->post('bookings/cancel/(:num)', 'Admin::bookingCancel/$1');
    $routes->get('bookings/(:num)', 'Admin::bookingView/$1');
    $routes->match(['GET', 'POST'], 'lead-statuses', 'Admin::leadStatuses');
    $routes->post('lead-statuses/update/(:num)', 'Admin::updateLeadStatus/$1');
    $routes->get('lead-statuses/delete/(:num)', 'Admin::deleteLeadStatus/$1');
    $routes->match(['GET', 'POST'], 'lead-custom-fields', 'Admin::leadCustomFields');
    $routes->post('lead-custom-fields/update/(:num)', 'Admin::updateLeadCustomField/$1');
    $routes->get('lead-custom-fields/delete/(:num)', 'Admin::deleteLeadCustomField/$1');
    $routes->match(['GET', 'POST'], 'quiz-settings', 'Admin::quizSettings');
    $routes->post('quiz-settings/save', 'Admin::quizSettingSave');
    $routes->get('quiz-settings/delete/(:num)', 'Admin::quizSettingDelete/$1');
    $routes->get('quiz-settings/toggle/(:num)/(:alpha)', 'Admin::quizSettingToggle/$1/$2');
    $routes->match(['GET', 'POST'], 'quiz-attempts', 'Admin::quizAttempts');
    $routes->match(['GET', 'POST'], 'quiz-attempts/quiz/(:num)', 'Admin::quizAttempts/$1');
    $routes->get('quiz-attempts/view/(:num)', 'Admin::quizAttemptView/$1');
    $routes->match(['GET', 'POST'], 'vapi-settings', 'Admin::vapiSettings');
    $routes->post('vapi/test-connection', 'Admin::vapiTestConnection');
    $routes->get('vapi/delete-binding/(:num)', 'Admin::vapiDeleteBinding/$1');
    $routes->match(['GET', 'POST'], 'vapi/score-history', 'Admin::vapiScoreHistory');
    $routes->match(['GET', 'POST'], 'vapi/score-history/binding/(:num)', 'Admin::vapiScoreHistory/$1');
    $routes->get('vapi/call-review/(:num)', 'Admin::vapiCallReview/$1');

    $routes->match(['GET', 'POST'], 'booking-schedules', 'Admin::bookingSchedules');
    $routes->get('booking-schedules/delete/(:num)', 'Admin::bookingScheduleDelete/$1');
    $routes->post('booking-schedules/shift/delete/(:num)', 'Admin::scheduleShiftDelete/$1');
    $routes->post('booking-schedules/slots/(:num)', 'Admin::bookingSlotsAJAX/$1');
    $routes->post('booking-schedules/slots', 'Admin::bookingSlotsAJAX');
    $routes->match(['GET', 'POST'], 'bookings', 'Admin::bookingList');
    $routes->get('bookings/view/(:num)', 'Admin::bookingView/$1');
    $routes->post('bookings/cancel/(:num)', 'Admin::bookingCancel/$1');
    $routes->match(['GET', 'POST'], 'booking-smtp', 'Admin::bookingSMTP');
    $routes->post('booking-smtp/test-connection', 'Admin::bookingSMTPTestConnection');
    $routes->post('booking-smtp/test-mail', 'Admin::bookingSMTPTestMail');
});

$routes->group('agent', ['filter' => 'agent'], function ($routes) {
    $routes->get('/', 'Agent::dashboard');
    $routes->get('documents', 'Agent::documents');
    $routes->get('documents/category/(:num)', 'Agent::documentsByCategory/$1');
    $routes->get('documents/view/(:num)', 'Agent::viewDocument/$1');
    $routes->get('leads', 'Agent::leads');
    $routes->get('leads/view/(:num)', 'Agent::viewLead/$1');
    $routes->post('leads/note/add/(:num)', 'Agent::addLeadNote/$1');
    $routes->post('leads/status/(:num)', 'Agent::leadUpdateStatus/$1');
    $routes->match(['GET', 'POST'], 'leads/sync-calls/(:num)', 'Agent::syncLeadCalls/$1');
    $routes->match(['GET', 'POST'], 'leads/book/(:num)', 'Agent::leadBook/$1');
    $routes->post('bookings/slots/(:num)', 'Agent::bookingSlotsAJAX/$1');
    $routes->post('bookings/slots', 'Agent::bookingSlotsAJAX');
    $routes->post('booking-slots/(:num)', 'Agent::bookingSlotsAJAX/$1');
    $routes->post('booking-slots', 'Agent::bookingSlotsAJAX');
    $routes->post('bookings/cancel/(:num)', 'Agent::leadBookingsCancel/$1');
    $routes->get('my-bookings', 'Agent::myBookings');
    $routes->get('my-bookings/(:alpha)', 'Agent::myBookings/$1');
    $routes->get('bookings/view/(:num)', 'Agent::bookingView/$1');
    $routes->get('bookings/(:num)', 'Agent::bookingView/$1');
    $routes->match(['GET', 'POST'], 'quizzes', 'Agent::quizzes');
    $routes->get('quizzes/start/(:num)', 'Agent::quizStart/$1');
    $routes->get('quizzes/take/(:num)', 'Agent::quizTake/$1');
    $routes->post('quizzes/answer', 'Agent::quizAnswerAjax');
    $routes->post('quizzes/finish', 'Agent::quizFinishAjax');
    $routes->get('quizzes/result/(:num)', 'Agent::quizResult/$1');
    $routes->get('mock-calls', 'Agent::mockCalls');
    $routes->get('mock-call-logs', 'Agent::mockCallLogs');
    $routes->get('mock-call-logs/(:num)', 'Agent::mockCallLogs/$1');
    $routes->match(['GET', 'POST'], 'mock-calls/sync/(:num)', 'Agent::mockCallSync/$1');
    $routes->post('mock-call-score/(:num)', 'Agent::mockCallScore/$1');
    $routes->get('mock-call-review/(:num)', 'Agent::mockCallReview/$1');
});

$routes->group('', ['filter' => 'auth'], function ($routes) {
    $routes->get('chat', 'ChatController::index');
    $routes->get('documents/download/(:num)', 'ChatController::downloadDocument/$1');
    $routes->post('chat/summarize', 'ChatController::summarize');
    $routes->post('chat/generate-questions', 'ChatController::generateQuestions');
    $routes->post('chat/suggest', 'ChatController::suggestQuestions');
    $routes->post('chat/ask', 'ChatController::ask');
    $routes->post('leads/call/initiate', 'ChatController::initiateLeadCall');
    $routes->post('chat/ask-call-transcript', 'ChatController::askCallTranscript');
    $routes->get('call/recording/(:num)', 'ChatController::downloadCallRecording/$1');
    $routes->get('call/recording/ct/(:any)', 'ChatController::downloadCallRecording/0/$1');
});

$routes->post('callback/cloudtalk', 'CloudTalkWebhook::handle');
$routes->get('callback/cloudtalk', 'CloudTalkWebhook::health');
