<?php



use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FingerDevicesControlller;
use App\Http\Controllers\MachineController;
use App\Http\Controllers\AttendanceDbController;
use App\Http\Controllers\EmployeeInfoController;

Route::get('/', function () {
    return view('welcome');
})->name('welcome');
Route::get('attended/{user_id}', '\App\Http\Controllers\AttendanceController@attended' )->name('attended');
Route::get('attended-before/{user_id}', '\App\Http\Controllers\AttendanceController@attendedBefore' )->name('attendedBefore');
Auth::routes(['register' => false, 'reset' => false]);

Route::group(['middleware' => ['auth', 'Role'], 'roles' => ['admin']], function () {
    Route::resource('/employees', '\App\Http\Controllers\EmployeeController');
    Route::resource('/employees', '\App\Http\Controllers\EmployeeController');
    Route::get('/attendance', '\App\Http\Controllers\AttendanceController@index')->name('attendance');
  
    Route::get('/latetime', '\App\Http\Controllers\AttendanceController@indexLatetime')->name('indexLatetime');
    Route::get('/leave', '\App\Http\Controllers\LeaveController@index')->name('leave');
    Route::get('/overtime', '\App\Http\Controllers\LeaveController@indexOvertime')->name('indexOvertime');

    Route::get('/admin', '\App\Http\Controllers\AdminController@index')->name('admin');

    Route::resource('/schedule', '\App\Http\Controllers\ScheduleController');

    Route::get('/check', '\App\Http\Controllers\CheckController@index')->name('check');
    Route::get('/sheet-report', '\App\Http\Controllers\CheckController@sheetReport')->name('sheet-report');
    Route::post('check-store','\App\Http\Controllers\CheckController@CheckStore')->name('check_store');
    

// new controller for connection to db

Route::get('/database_attendance', [AttendanceDbController::class, 'index'])->name('admin.attendance');
Route::get('/database_employee', [EmployeeInfoController::class, 'index'])->name('admin.employee');

Route::get('/sync_attendance', [MachineController::class, 'sync_attendance'])->name('machine.sync_attendance');
Route::get('/sync_employee_info', [MachineController::class, 'sync_employee_info'])->name('machine.sync_employee_info');




    //from zkteco library 

    // Route::get('/', [MachineController::class, 'index'])->name('machine.home');
Route::get('/test-sound', [MachineController::class, 'test_sound'])->name('machine.testsound');
Route::get('/device-sleep', [MachineController::class, 'device_sleep'])->name('machine.sleep');
Route::get('/device-information', [MachineController::class, 'device_information'])->name('machine.deviceinformation');
// Route::get('/device-data', [MachineController::class, 'device_data'])->name('machine.devicedata');
Route::get('/device-data-user', [MachineController::class, 'device_data_user'])->name('machine.devicedata.user');
Route::get('/device-data-attendance', [MachineController::class, 'device_data_attendance'])->name('machine.devicedata.attendances');
Route::get('/device-data/clear-attendance', [MachineController::class, 'device_data_clear_attendance'])->name('machine.devicedata.clear.attendance');
Route::get('/device-restart', [MachineController::class, 'device_restart'])->name('machine.devicerestart');
Route::get('/clear_attendance', [MachineController::class, 'device_data_clear_attendance'])->name('machine.clear_attendance_data');
Route::get('/device-shutdown', [MachineController::class, 'device_shutdown'])->name('machine.deviceshutdown');
Route::get('/device-resume', [MachineController::class, 'device_resume'])->name('machine.deviceresume');
Route::get('/device-settime', [MachineController::class, 'device_settime'])->name('machine.devicesettime');

Route::post('/device-setip', [MachineController::class, 'device_setip'])->name('machine.devicesetip');
Route::get('/device-adduser', [MachineController::class, 'device_adduser'])->name('machine.deviceadduser');

Route::post('/device-setuser', [MachineController::class, 'device_setuser'])->name('machine.devicesetuser');
Route::get('/device-removeuser-all', [MachineController::class, 'device_removeuser_all'])->name('machine.deviceremoveuserall');
Route::get('/device-removeuser-single/{id}', [MachineController::class, 'device_removeuser_single'])->name('machine.deviceremoveusersingle');
Route::get('/device-viewuser-single/[id]', [MachineController::class, 'device_viewuser_single'])->name('machine.deviceviewusersingle');


    // Fingerprint Devices
    Route::resource('/finger_device', '\App\Http\Controllers\BiometricDeviceController');

    Route::delete('finger_device/destroy', '\App\Http\Controllers\BiometricDeviceController@massDestroy')->name('finger_device.massDestroy');
    Route::get('finger_device/{fingerDevice}/employees/add', '\App\Http\Controllers\BiometricDeviceController@addEmployee')->name('finger_device.add.employee');
    Route::get('finger_device/{fingerDevice}/get/attendance', '\App\Http\Controllers\BiometricDeviceController@getAttendance')->name('finger_device.get.attendance');
    // Temp Clear Attendance route
    Route::get('finger_device/clear/attendance', function () {
        $midnight = \Carbon\Carbon::createFromTime(23, 50, 00);
        $diff = now()->diffInMinutes($midnight);
        dispatch(new ClearAttendanceJob())->delay(now()->addMinutes($diff));
        toast("Attendance Clearance Queue will run in 11:50 P.M}!", "success");

        return back();
    })->name('finger_device.clear.attendance');
    

});

Route::group(['middleware' => ['auth']], function () {

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



    

});

// Route::get('/attendance/assign', function () {
//     return view('attendance_leave_login');
// })->name('attendance.login');

// Route::post('/attendance/assign', '\App\Http\Controllers\AttendanceController@assign')->name('attendance.assign');


// Route::get('/leave/assign', function () {
//     return view('attendance_leave_login');
// })->name('leave.login');

// Route::post('/leave/assign', '\App\Http\Controllers\LeaveController@assign')->name('leave.assign');


// Route::get('{any}', 'App\http\controllers\VeltrixController@index');