<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


/*
 * if no pro performer, then redirect to /login
 * [Cell Number] [Password] field -> proLogInWithPassword -> /pro/dashboard
 * -> they are authenticated in... see the home dashboard... logout button to -> /login
 */


Route::get('login', 'LoginController@showLoginForm')->name('login');
Route::post('login', 'LoginController@login');

Route::get('request_password_reset', 'LoginController@showRequestPasswordReset')->name('request_password_reset');
Route::post('request_password_reset', 'LoginController@processRequestPasswordReset')->name('process_request_password_reset');
Route::get('self_reset_password', 'LoginController@showSelfResetPassword')->name('self_reset_password');
Route::post('self_reset_password', 'LoginController@processSelfResetPassword')->name('process_self_reset_password');

Route::get('/pro_log_in_with_session_key/{sessionKey}', 'LoginController@loginWithSessionKey')->name('login_with_session_key');

Route::post('logout', 'LoginController@logout')->name('logout');

Route::post('/confirm_sms_auth_token', 'HomeController@postConfirmSmsAuthToken')->name('post-confirm_sms_auth_token');
Route::post('/resend_sms_auth_token', 'HomeController@resendSmsAuthToken')->name('post-resend_sms_auth_token');
Route::post('/set_password', 'HomeController@postSetPassword')->name('post-set_password');
Route::post('/set_security_questions', 'HomeController@postSetSecurityQuestions')->name('post-set_security_questions');

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

    //complete authentication

    Route::get('/confirm_sms_auth_token', 'HomeController@confirmSmsAuthToken')->name('confirm_sms_auth_token');

    Route::get('/set_password', 'HomeController@setPassword')->name('set_password');

    Route::get('/set_security_questions', 'HomeController@setSecurityQuestions')->name('set_security_questions');

    Route::get('/blank', 'HomeController@blank')->name('blank');

    Route::get('/', 'HomeController@dashboard')->name('dashboard');

    Route::get('/new-patient', 'HomeController@newPatient')->name('new-patient');

    Route::get('/patients/{filter?}', 'HomeController@patients')->name('patients');

    Route::get('/unmapped-sms/{filter?}', 'HomeController@unmappedSMS')->name('unmapped-sms');

    Route::name('practice-management.')->prefix('practice-management')->group(function () {
        Route::get('rates', 'PracticeManagementController@rates')->name('rates');
        Route::get('dashboard', 'PracticeManagementController@dashboard')->name('dashboard');
        Route::get('previous-bills', 'PracticeManagementController@previousBills')->name('previousBills');
        Route::get('financial-transactions', 'PracticeManagementController@financialTransactions')->name('financialTransactions');
        Route::get('pending-bills-to-sign', 'PracticeManagementController@pendingBillsToSign')->name('pendingBillsToSign');
        Route::get('hr', 'PracticeManagementController@hr')->name('hr');
        Route::get('direct-deposit-settings', 'PracticeManagementController@directDepositSettings')->name('directDepositSettings');
        Route::get('w9', 'PracticeManagementController@w9')->name('w9');
        Route::get('contract', 'PracticeManagementController@contract')->name('contract');
        Route::get('notes/{filter?}', 'PracticeManagementController@notes')->name('notes');
        Route::get('bills/{filter?}', 'PracticeManagementController@bills')->name('bills');
        Route::get('my-text-shortcuts', 'PracticeManagementController@myTextShortcuts')->name('myTextShortcuts');
    });

    Route::name('patients.view.')->prefix('patients/view/{patient}')->group(function () {
        Route::get('intake', 'PatientController@intake')->name('intake');
        Route::get('', 'PatientController@dashboard')->name('dashboard');
        Route::get('care-plan', 'PatientController@carePlan')->name('care-plan');
        Route::get('medications', 'PatientController@medications')->name('medications');
        Route::get('dx-and-focus-areas', 'PatientController@dxAndFocusAreas')->name('dx-and-focus-areas');
        Route::get('care-team', 'PatientController@careTeam')->name('care-team');
        Route::get('measurements', 'PatientController@measurements')->name('measurements');
        Route::get('labs-and-studies', 'PatientController@labsAndStudies')->name('labs-and-studies');
        Route::get('history', 'PatientController@history')->name('history');
        Route::get('sms', 'PatientController@sms')->name('sms');
        Route::get('sms-numbers', 'PatientController@smsNumbers')->name('sms-numbers');
        Route::get('documents', 'PatientController@documents')->name('documents');
        Route::get('immunizations', 'PatientController@immunizations')->name('immunizations');
        Route::get('allergies', 'PatientController@allergies')->name('allergies');
        Route::get('action-items', 'PatientController@actionItems')->name('action-items');
        Route::get('notes', 'PatientController@notes')->name('notes');
        Route::name('notes.view.')->prefix('notes/view/{note}')->group(function () {
            Route::get('', 'NoteController@dashboard')->name('dashboard');
        });
        Route::get('flowsheets', 'PatientController@flowSheets')->name('flowsheets');
        Route::get('demographics', 'PatientController@demographics')->name('demographics');
        Route::get('account', 'PatientController@account')->name('account');
        Route::get('care-checklist', 'PatientController@careChecklist')->name('care-checklist');
        Route::get('documents', 'PatientController@documents')->name('documents');
        Route::get('education', 'PatientController@education')->name('education');
        Route::get('messaging', 'PatientController@messaging')->name('messaging');
        Route::get('duplicate', 'PatientController@duplicate')->name('duplicate');
        Route::get('care-months', 'PatientController@careMonths')->name('care-months');
        Route::name('care-months.view.')->prefix('care-months/view/{careMonth}')->group(function () {
            Route::get('', 'CareMonthController@dashboard')->name('dashboard');
        });
    });

    // load template set
    Route::get('/note-template-set/exam/{exam}/{template}', 'HomeController@noteExamTemplateSet');
    Route::get('/note-template-set/{section}/{template}', 'HomeController@noteTemplateSet');

    // Patient suggest
    Route::get('/patients-suggest', 'HomeController@patientsSuggest');

    // embeddable sections
    Route::get('/embed/{patient}/{section}/{selectable}', 'PatientController@embedSection')->name('embed-section');

    // AJAX presence poll
    Route::get('/patients/{patient}/presence', 'PatientController@presence');

    // 2-pane outer page housing lhs (practice management) and rhs (video call)
    Route::get('/mc/{fragment?}', 'HomeController@mc')
        ->where('fragment', '.*')
        ->name('mc');

    // pro meeting
    Route::get('/pro/meet/{uid?}', 'PracticeManagementController@meet');
    Route::get('/pro/get-opentok-session-key/{uid}', 'PracticeManagementController@getOpentokSessionKey');

    //Notes stuff
    Route::get('/note/{note_uid}', 'NoteController@renderNote')->name('render-note');
    Route::get('/section_create_form/{note_uid}/{section_template_uid}', 'NoteController@sectionCreateForm')->name('section_create_form');
    Route::get('/section_update_form/{section_uid}', 'NoteController@sectionUpdateForm')->name('section_update_form');
    Route::post("/process_form_submit", 'NoteController@processFormSubmit')->name('process_form_submit');
    Route::get("/get-default-section-data/{section}/{uid}", 'NoteController@getDefaultValueForSection')->name('get_default_section_data');

    Route::get("/log_in_as", 'HomeController@logInAs')->name('log-in-as');
    Route::post("/process-log_in_as", 'HomeController@processLogInAs')->name('process-log-in-as');
    Route::post("/back_to_admin_pro", 'HomeController@backToAdminPro')->name('back-to-admin-pro');
});
