<?php 

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Artisan;
use App\Http\Controllers\Backend\RoleController;
use App\Http\Controllers\Backend\Visit\VisitController;
use App\Http\Controllers\DailyLeaveController;
use App\Http\Controllers\Backend\Leave\LeaveTypeController;
use App\Http\Controllers\Backend\Support\SupportController;
use App\Http\Controllers\Backend\Leave\AssignLeaveController;
use App\Http\Controllers\Notification\NotificationController;
use App\Http\Controllers\Backend\Leave\LeaveRequestController;
use App\Http\Controllers\Backend\Employee\AppointmentController;
use App\Http\Controllers\Backend\Attendance\AttendanceController;
use App\Http\Controllers\Backend\Department\DepartmentController;
use App\Http\Controllers\Backend\Designation\DesignationController;


Route::group(['prefix' => 'hrm', 'middleware' => ['xss', 'admin', 'MaintenanceMode']], function () {
    Route::middleware(['FeatureCheck:leaves'])->group(function () {
        Route::group(['prefix' => 'leave'], function () {
            //leave type routes start
            Route::get('/', [LeaveTypeController::class, 'index'])->name('leave.index')->middleware('PermissionCheck:leave_type_read');
            Route::post('delete-data', [LeaveTypeController::class, 'deleteData'])->name('leave.delete_data')->middleware('PermissionCheck:leave_type_delete');
            Route::post('status-change', [LeaveTypeController::class, 'statusUpdate'])->name('leave.statusUpdate')->middleware('PermissionCheck:leave_type_update');
            Route::get('create-modal', [LeaveTypeController::class, 'createModal'])->name('leave.create_modal')->middleware('PermissionCheck:leave_type_create');
            Route::get('edit-modal/{id}', [LeaveTypeController::class, 'editModal'])->name('leave.edit_modal')->middleware('PermissionCheck:leave_type_update');
            Route::post('update/{leave}', [LeaveTypeController::class, 'update'])->name('leave.update')->middleware('PermissionCheck:leave_type_update');

            Route::get('data-table', [LeaveTypeController::class, 'dataTable'])->name('leave.dataTable')->middleware('PermissionCheck:leave_type_read');
            Route::get('create', [LeaveTypeController::class, 'create'])->name('leave.create')->middleware('PermissionCheck:leave_type_create');
            Route::post('store', [LeaveTypeController::class, 'store'])->name('leave.store')->middleware('PermissionCheck:leave_type_create');
            Route::get('show/{leaveType}', [LeaveTypeController::class, 'show'])->name('leave.show')->middleware('PermissionCheck:leave_type_read');
            Route::get('edit/{leaveType}', [LeaveTypeController::class, 'edit'])->name('leave.edit')->middleware('PermissionCheck:leave_type_update');
            Route::patch('update/{leaveType}', [LeaveTypeController::class, 'update'])->name('leave.update')->middleware('PermissionCheck:leave_type_update');
            Route::get('delete/{leaveType}', [LeaveTypeController::class, 'delete'])->name('leave.delete')->middleware('PermissionCheck:leave_type_delete');
            //leave type routes end
            //assign leave routes start
            Route::group(['prefix' => 'assign'], function () {
                Route::get('/', [AssignLeaveController::class, 'index'])->name('assignLeave.index')->middleware('PermissionCheck:leave_assign_read');

                Route::post('delete-data', [AssignLeaveController::class, 'deleteData'])->name('assignLeave.delete_data')->middleware('PermissionCheck:leave_assign_delete');
                Route::post('status-change', [AssignLeaveController::class, 'statusUpdate'])->name('assignLeave.statusUpdate')->middleware('PermissionCheck:leave_assign_update');

                Route::get('create', [AssignLeaveController::class, 'create'])->name('assignLeave.create')->middleware('PermissionCheck:leave_assign_create');
                Route::post('store', [AssignLeaveController::class, 'store'])->name('assignLeave.store')->middleware('PermissionCheck:leave_assign_create');
                Route::get('show/{assignLeave}', [AssignLeaveController::class, 'show'])->name('assignLeave.show')->middleware('PermissionCheck:leave_assign_read');
                // annual leave summary
                Route::get('leave-summary/{assignLeave}', [AssignLeaveController::class, 'leaveSummery'])->name('assignLeave.leave_summery')->middleware('PermissionCheck:leave_assign_read');
                Route::get('annual-leave-summary/transfer/{leaveYear}', [AssignLeaveController::class, 'leaveTransferIndex'])->name('assignLeave.transfer.add')->middleware('PermissionCheck:leave_assign_update');
                Route::post('annual-leave-summary/transfer/{leaveYear}', [AssignLeaveController::class, 'leaveTransfer'])->name('assignLeave.transfer')->middleware('PermissionCheck:leave_assign_update');
                
                Route::get('edit/{assignLeave}', [AssignLeaveController::class, 'edit'])->name('assignLeave.edit')->middleware('PermissionCheck:leave_assign_update');
                Route::post('update/{assignLeave}', [AssignLeaveController::class, 'update'])->name('assignLeave.update')->middleware('PermissionCheck:leave_assign_update');
                Route::get('data-table', [AssignLeaveController::class, 'dataTable'])->name('assignLeave.dataTable')->middleware('PermissionCheck:leave_assign_read');
                Route::get('delete/{assignLeave}', [AssignLeaveController::class, 'delete'])->name('assignLeave.delete')->middleware('PermissionCheck:leave_assign_delete');
                //assign leave routes end
            });

            // DailyLeave old routes
            // Route::group(['prefix' => 'daily-leave'],function(){
            //     Route::get('/',[DailyLeaveController::class,'index'])->name('dailyLeave.index')->middleware('PermissionCheck:daily_leave_read');
            // });

            //apply for leave routes start
            Route::group(['prefix' => 'request'], function () {
                Route::get('/', [LeaveRequestController::class, 'index'])->name('leaveRequest.index')->middleware('PermissionCheck:leave_request_read');

                Route::post('delete-data', [LeaveRequestController::class, 'deleteData'])->name('leaveRequest.delete_data')->middleware('PermissionCheck:leave_request_delete');
                Route::post('status-change', [LeaveRequestController::class, 'statusUpdate'])->name('leaveRequest.statusUpdate')->middleware('PermissionCheck:leave_request_update');

                Route::get('create', [LeaveRequestController::class, 'create'])->name('leaveRequest.create')->middleware('PermissionCheck:leave_request_create');
                Route::post('store', [LeaveRequestController::class, 'store'])->name('leaveRequest.store')->middleware('PermissionCheck:leave_request_create');
                Route::patch('update', [LeaveRequestController::class, 'update'])->name('leaveRequest.update')->middleware('PermissionCheck:leave_request_update');
                Route::get('data-table', [LeaveRequestController::class, 'dataTable'])->name('leaveRequest.dataTable')->middleware('PermissionCheck:leave_request_read');
                Route::get('profile-data-table', [LeaveRequestController::class, 'profileDataTable'])->name('leaveRequest.profileDataTable')->middleware('PermissionCheck:leave_request_read');
                Route::get('show/{leaveRequest}', [LeaveRequestController::class, 'show'])->name('leaveRequest.show')->middleware('PermissionCheck:leave_request_read');
                Route::get('view/{leaveRequest}', [LeaveRequestController::class, 'pdfView'])->name('leaveRequest.view')->middleware('PermissionCheck:leave_request_read');
                Route::get('delete/{leaveRequest}', [LeaveRequestController::class, 'delete'])->name('leaveRequest.delete')->middleware('PermissionCheck:leave_request_delete');
                Route::get('approve-or-reject/{leaveRequest}/{status_id}', [LeaveRequestController::class, 'requestApproveOrReject'])->name('leaveRequest.approveOrReject')->middleware('PermissionCheck:leave_request_approve');
                //assign leave routes end
            });
        });
        // daily leave routes start
        Route::group(['prefix' => 'daily-leave'], function () {
            Route::get('/', [DailyLeaveController::class, 'index'])->name('daily_leave.index')->middleware('PermissionCheck:daily_leave_read');
            Route::get('create', [DailyLeaveController::class, 'create'])->name('daily_leave.create')->middleware('PermissionCheck:daily_leave_read');
            Route::post('store', [DailyLeaveController::class, 'store'])->name('daily_leave.store')->middleware('PermissionCheck:daily_leave_read');
            Route::patch('update', [DailyLeaveController::class, 'update'])->name('daily_leave.update')->middleware('PermissionCheck:daily_leave_read');
            Route::post('delete-data', [DailyLeaveController::class, 'deleteData'])->name('daily_leave.delete_data')->middleware('PermissionCheck:daily_leave_read');
            Route::post('status-change', [DailyLeaveController::class, 'statusUpdate'])->name('daily_leave.statusUpdate')->middleware('PermissionCheck:daily_leave_read');
            Route::get('approved-or-reject/{dailyLeave}/{status_id}', [DailyLeaveController::class, 'requestApproveOrReject'])->name('daily_leave.approveOrReject')->middleware('PermissionCheck:daily_leave_read');
            Route::get('delete/{dailyLeave}', [DailyLeaveController::class, 'delete'])->name('daily_leave.delete')->middleware('PermissionCheck:daily_leave_read');
        });

    });

    Route::middleware(['FeatureCheck:attendance'])->group(function () {
        //attendance start
        Route::group(['prefix' => 'attendance'], function () {
            Route::get('/', [AttendanceController::class, 'index'])->name('attendance.index')->middleware('PermissionCheck:attendance_read');
            Route::get('/summary', [AttendanceController::class, 'summary'])->name('attendance.summary')->middleware('PermissionCheck:attendance_read');
            Route::get('/absents', [AttendanceController::class, 'absents'])->name('attendance.absents')->middleware('PermissionCheck:attendance_read');
         
            Route::get('add', [AttendanceController::class, 'checkIn'])->name('attendance.check-in')->middleware('PermissionCheck:attendance_create');
            Route::get('edit/check-in/{attendance}', [AttendanceController::class, 'checkInEdit'])->name('attendance.checkInEdit')->middleware('PermissionCheck:attendance_update');

            Route::get('check-out/{attendance_id}', [AttendanceController::class, 'checkOut'])->name('attendance.checkout')->middleware('PermissionCheck:attendance_update');
            Route::post('store', [AttendanceController::class, 'store'])->name('attendance.store')->middleware('PermissionCheck:attendance_create');
            Route::get('edit/{attendance_id}', [AttendanceController::class, 'show'])->name('attendance.edit')->middleware('PermissionCheck:attendance_update');
            Route::patch('update/{attendance_id}', [AttendanceController::class, 'update'])->name('attendance.update')->middleware('PermissionCheck:attendance_update');
            Route::get('delete/{attendance_id}', [AttendanceController::class, 'delete'])->name('attendance.delete')->middleware('PermissionCheck:attendance_delete');
            Route::get('show-image-in-modal/{attendance_id}/{type}', [AttendanceController::class, 'showImageInModal'])->name('attendance.show-image-in-modal')->middleware('PermissionCheck:attendance_read');
        });
        //attendance end
    });


    //designation start
    Route::group(['prefix' => 'designation'], function () {
        Route::get('/',            [DesignationController::class, 'index'])->name('designation.index')->middleware('PermissionCheck:designation_read');
        Route::post('delete-data', [DesignationController::class, 'deleteData'])->name('designation.delete_data')->middleware('PermissionCheck:designation_delete');
        Route::post('status-change', [DesignationController::class, 'statusUpdate'])->name('designation.statusUpdate')->middleware('PermissionCheck:designation_update');
        Route::get('create-modal', [DesignationController::class, 'createModal'])->name('designation.create_modal')->middleware('PermissionCheck:designation_create');
        Route::get('edit-modal/{id}', [DesignationController::class, 'editModal'])->name('designation.edit_modal')->middleware('PermissionCheck:designation_update');
        Route::post('update/{designation}', [DesignationController::class, 'update'])->name('designation.update')->middleware('PermissionCheck:designation_update');

        Route::get('create', [DesignationController::class, 'create'])->name('designation.create')->middleware('PermissionCheck:designation_create');
        Route::get('data-table', [DesignationController::class, 'dataTable'])->name('designation.dataTable')->middleware('PermissionCheck:designation_read');
        Route::post('store', [DesignationController::class, 'store'])->name('designation.store')->middleware('PermissionCheck:designation_create');
        Route::get('show/{designation}', [DesignationController::class, 'show'])->name('designation.show')->middleware('PermissionCheck:designation_read');
        Route::get('edit/{designation}', [DesignationController::class, 'edit'])->name('designation.edit')->middleware('PermissionCheck:designation_update');
        Route::get('delete/{designation}', [DesignationController::class, 'delete'])->name('designation.delete')->middleware('PermissionCheck:designation_delete');
        // new delete array data
    });
    //designation end

    //department start
    Route::group(['prefix' => 'department'], function () {
        Route::get('/', [DepartmentController::class, 'index'])->name('department.index')->middleware('PermissionCheck:department_read');
        Route::post('status-change', [DepartmentController::class, 'statusUpdate'])->name('department.statusUpdate')->middleware('PermissionCheck:department_update');
        Route::post('delete-data', [DepartmentController::class, 'deleteData'])->name('department.delete_data')->middleware('PermissionCheck:department_delete');
        Route::get('create-modal', [DepartmentController::class, 'createModal'])->name('department.create_modal')->middleware('PermissionCheck:department_create');
        Route::get('edit-modal/{id}', [DepartmentController::class, 'editModal'])->name('department.edit_modal')->middleware('PermissionCheck:department_update');
        Route::post('update/{department}', [DepartmentController::class, 'update'])->name('department.update')->middleware('PermissionCheck:department_update');

        Route::get('create', [DepartmentController::class, 'create'])->name('department.create')->middleware('PermissionCheck:department_create');
        Route::get('data-table', [DepartmentController::class, 'dataTable'])->name('department.dataTable')->middleware('PermissionCheck:department_read');
        Route::post('store', [DepartmentController::class, 'store'])->name('department.store')->middleware('PermissionCheck:department_create');
        Route::get('show/{department}', [DepartmentController::class, 'show'])->name('department.show')->middleware('PermissionCheck:department_read');
        Route::get('edit/{department}', [DepartmentController::class, 'edit'])->name('department.edit')->middleware('PermissionCheck:department_update');
        Route::get('delete/{department}', [DepartmentController::class, 'delete'])->name('department.delete')->middleware('PermissionCheck:department_delete');
    });
    //department end

    //roles start
    Route::group(['prefix' => 'roles'], function () {
        Route::get('/', [RoleController::class, 'index'])->name('roles.index')->middleware('PermissionCheck:role_read');
        Route::post('status-change', [RoleController::class, 'statusUpdate'])->name('roles.statusUpdate')->middleware('PermissionCheck:role_update');
        Route::post('delete-data', [RoleController::class, 'deleteData'])->name('roles.delete_data')->middleware('PermissionCheck:role_delete');
        Route::get('create-modal', [RoleController::class, 'createModal'])->name('role.create_modal')->middleware('PermissionCheck:role_create');

        Route::get('create', [RoleController::class, 'create'])->name('roles.create')->middleware('PermissionCheck:role_create');
        Route::post('store', [RoleController::class, 'store'])->name('roles.store')->middleware('PermissionCheck:role_create');
        Route::get('show/{role}', [RoleController::class, 'show'])->name('roles.show')->middleware('PermissionCheck:role_read');
        Route::get('edit/{role}', [RoleController::class, 'edit'])->name('roles.edit')->middleware('PermissionCheck:role_update');
        Route::patch('update/{role}', [RoleController::class, 'update'])->name('roles.update')->middleware('PermissionCheck:role_update');
        Route::get('delete/{role}', [RoleController::class, 'destroy'])->name('roles.destroy')->middleware('PermissionCheck:role_delete');
        Route::get('data-table', [RoleController::class, 'dataTable'])->name('roles.dataTable')->middleware('PermissionCheck:role_read');
        Route::post('change-role', [RoleController::class, 'changeRole'])->name('roles.change')->middleware('PermissionCheck:role_update');
        Route::post('change-login', [RoleController::class, 'changeLogin'])->name('roles.change_login')->middleware('PermissionCheck:role_update');
    });
    //roles end

    //shift end
    
    Route::middleware(['FeatureCheck:appointment'])->group(function () {
        //appointment start
        Route::group(['prefix' => 'appointment'], function () {
            Route::get('/', [AppointmentController::class, 'list'])->name('appointment.index')->middleware('PermissionCheck:appointment_read');

            Route::get('create', [AppointmentController::class, 'create'])->name('appointment.create')->middleware('PermissionCheck:appointment_create');
            Route::post('store', [AppointmentController::class, 'store'])->name('appointment.store')->middleware('PermissionCheck:appointment_read');
            Route::patch('update', [AppointmentController::class, 'update'])->name('appointment.update')->middleware('PermissionCheck:appointment_create');
            Route::get('data-table', [AppointmentController::class, 'dataTable'])->name('appointment.dataTable')->middleware('PermissionCheck:appointment_read');
            Route::get('profile-data-table', [AppointmentController::class, 'profileDataTable'])->name('appointment.profileDataTable');
            Route::get('show/{appointment}', [AppointmentController::class, 'show'])->name('appointment.show')->middleware('PermissionCheck:appointment_read');
            Route::get('view/{appointment}', [AppointmentController::class, 'pdfView'])->name('appointment.view')->middleware('PermissionCheck:appointment_read');
            Route::get('delete/{appointment}', [AppointmentController::class, 'delete'])->name('appointment.delete')->middleware('PermissionCheck:appointment_delete');
            //appointment request
            Route::get('table', [AppointmentController::class, 'table'])->name('appointment.table')->middleware('PermissionCheck:appointment_read');
        });
    });


    Route::middleware(['FeatureCheck:support'])->group(function () {
        //support routes start
        Route::group(['prefix' => 'support'], function () {
            Route::get('ticket/list', [SupportController::class, 'index'])->name('supportTicket.index');
            Route::get('ticket/create', [SupportController::class, 'create'])->name('supportTicket.create')->middleware('PermissionCheck:support_ticket_create');
            Route::post('ticket/store', [SupportController::class, 'store'])->name('supportTicket.store')->middleware('PermissionCheck:support_ticket_create');
            Route::get('user/ticket', [SupportController::class, 'staffTicket'])->name('user.supportTicket')->middleware('PermissionCheck:support_ticket_read');
            Route::get('ticket/reply/{ticket}/{code}', [SupportController::class, 'ticketReply'])->name('supportTicket.reply')->middleware('PermissionCheck:support_ticket_reply');
            Route::post('ticket/reply/{ticket}', [SupportController::class, 'ticketReplyStore'])->name('supportTicket.reply.store')->middleware('PermissionCheck:support_ticket_reply');
            Route::get('data-table', [SupportController::class, 'dataTable'])->name('supportTicket.dataTable')->middleware('PermissionCheck:support_ticket_read');
            Route::get('data-table/{id}', [SupportController::class, 'userTicketDatatable'])->name('user.supportTicket.dataTable')->middleware('PermissionCheck:support_ticket_read');
            Route::get('ticket/delete/{id}', [SupportController::class, 'delete'])->name('supportTicket.delete')->middleware('PermissionCheck:support_ticket_delete');
            Route::get('ticket/assign/{id}', [SupportController::class, 'assignTicket'])->name('supportTicket.assign')->middleware('PermissionCheck:support_ticket_assign');

            Route::post('delete-data', [SupportController::class, 'deleteData'])->name('supportTicket.delete_data')->middleware('PermissionCheck:support_ticket_delete');
        });
        //support routes end
    });

    Route::middleware(['FeatureCheck:visit'])->group(function () {
        //Visit start
        Route::group(['prefix' => 'user'], function () {
            //Visit
            Route::get('{id}/visit', [VisitController::class, 'visit'])->name('visit.user')->middleware('PermissionCheck:visit_read');
            Route::get('{id}/visit-history', [VisitController::class, 'visitHistory'])->name('visit.history')->middleware('PermissionCheck:visit_read');
            Route::get('visit-datatable/{user_id}', [VisitController::class, 'visitDatatable'])->name('user.visit.dataTable')->middleware('PermissionCheck:visit_read');
            Route::get('visit-history-datatable', [VisitController::class, 'visitHistoryDatatable'])->name('visit.history.dataTable')->middleware('PermissionCheck:visit_read');
            Route::get('visit-details/{id}', [VisitController::class, 'visitDetails'])->name('visit.details')->middleware('PermissionCheck:visit_read');
            Route::get('visit/{id}/schedules', [VisitController::class, 'visitDetailsSchedules'])->name('visit.details.schedules');
        });

        Route::group(['prefix' => 'visit'], function () {
            Route::get('/', [VisitController::class, 'index'])->name('visit.index')->middleware('PermissionCheck:visit_read');
        });
        //Visit end
    });

    //expense start
    Route::group(['prefix' => 'notification'], function () {
        Route::get('/', [NotificationController::class, 'index'])->name('notification.index');
        Route::get('/seen/{id}', [NotificationController::class, 'readMyNotification'])->name('readNotification');
        Route::post('/bulk-seen', [NotificationController::class, 'bulkSeen'])->name('notification.bulk-seen');
        Route::post('/delete', [NotificationController::class, 'delete'])->name('notification.delete');
    });
    //expire notification
    Route::get('/expire_notification', [NotificationController::class, 'expireIndex'])->name('expire.notification.index');

    // dummy data for location
    Route::get('/seed-location-logs', function () {
        Artisan::call('db:seed', ['--class' => 'LocationLogsTableSeeder']);
        return 'Location logs seeding completed.';
    });
});
