<?php

use App\Http\Middleware\CheckPermission;
use Illuminate\Support\Facades\Route;
use Modules\Admin\app\Http\Controllers\AdminController;
use Modules\Admin\app\Http\Controllers\BannerController;
use Modules\Admin\app\Http\Controllers\CategoryController;
use Modules\Admin\app\Http\Controllers\ClientController;
use Modules\Admin\app\Http\Controllers\CountryController;
use Modules\Admin\app\Http\Controllers\CustomThemeController;
use Modules\Admin\app\Http\Controllers\DashboardController;
use Modules\Admin\app\Http\Controllers\JiraController;
use Modules\Admin\app\Http\Controllers\LeaveManagementController;
use Modules\Admin\app\Http\Controllers\SettingController;
use Modules\Admin\app\Http\Controllers\TicketController;
use Modules\Admin\app\Http\Controllers\TimekeepingController;
use Modules\Admin\app\Http\Controllers\TrackingController;
use Modules\Admin\app\Http\Controllers\CriteriasController;
use Modules\Admin\app\Http\Controllers\ProfileController;
use Modules\Admin\app\Http\Controllers\TestCaseForSprintController;
use Modules\Admin\app\Http\Middleware\AdminMiddleware;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
 */

Route::middleware('api')
    ->prefix('v1/admin')
    ->group(function () {
        // NOTE not login
        Route::group([], function () {
            Route::post('login', [AdminController::class, 'login']);
            Route::post('reset-password', [AdminController::class, 'resetPassword']);
            Route::get('forgot-password', [AdminController::class, 'forgotPassword']);
        });

        // NOTE after login
        Route::group([
            'middleware' => AdminMiddleware::class,
        ], function () {
            Route::get('logout', [AdminController::class, 'logout']);
            Route::get('detail', [AdminController::class, 'detail']);
            Route::post('change-password', [AdminController::class, 'changePassword']);

            Route::group([
                'prefix' => 'setting',
            ], function () {
                Route::get('/', [SettingController::class, 'index']);
                Route::post('/', [SettingController::class, 'updateOrCreate']);
                Route::get('/clear-cache', [SettingController::class, 'clearCache']);
            });

            Route::group([
                'prefix' => 'client',
            ], function () {
                Route::get('/get', [ClientController::class, 'get']);
                Route::post('/create', [ClientController::class, 'create']);
                Route::post('/update', [ClientController::class, 'update']);
                Route::get('/delete', [ClientController::class, 'delete']);
                Route::post('/updates', [ClientController::class, 'updates']);
                Route::post('/deletes', [ClientController::class, 'deletes']);
            });

            Route::group([
                'prefix' => 'banner',
            ], function () {
                Route::get('/all', [BannerController::class, 'all']);
                Route::post('/create', [BannerController::class, 'create']);
                Route::post('/update', [BannerController::class, 'update']);
                Route::get('/delete', [BannerController::class, 'delete']);
                Route::post('/updates', [BannerController::class, 'updates']);
                Route::post('/deletes', [BannerController::class, 'deletes']);
            });


            Route::group([
                'prefix' => 'custom-theme',
            ], function () {
                Route::get('/', [CustomThemeController::class, 'index']);
                Route::post('/', [CustomThemeController::class, 'updateOrCreate']);
            });
            Route::group([
                'prefix' => 'h-country',
            ], function () {
                Route::get('/', [CountryController::class, 'all']);
            });

            Route::group([
                'prefix' => 'dashboard',
            ], function () {
                Route::get('/get', [DashboardController::class, 'get']);
                Route::get('/statistics-search-sn-by-month', [DashboardController::class, 'statisticSearchSNByMonth']);
                Route::get('/statistics-revenues-by-month', [DashboardController::class, 'statisticRevenuesByMonth']);
            });
            Route::group([
                'prefix' => 'jira',
            ], function () {
                Route::get('/fetch-issues', [JiraController::class, 'fetchAllIssues']);
                Route::get('/all-project', [JiraController::class, 'getAllProject']);
                Route::get('/get-detail-project-by-id', [JiraController::class, 'getDetailsProjectsById']);
                Route::get('/get-all-board-by-id-project', [JiraController::class, 'getAllBoardByIdProjects']);
                Route::get('/get-all-sprint-by-id-board', [JiraController::class, 'getAllSprintByIdBoard']);
                Route::get('/get-all-issue-by-id-sprint', [JiraController::class, 'getAllIssueByIdSprint']);

                Route::get('/all-issue-by-project', [JiraController::class, 'fetchIssuesByProject']);
                Route::get('/worklogs', [JiraController::class, 'getAllUserWorkLogs'])->middleware('check.permission:admin.staff');
                Route::get('/allocation', [JiraController::class, 'getAllUserDoing'])->middleware('check.permission:admin.staff');
                Route::get('/issue/detail', [JiraController::class, 'getDetailIssueById'])->middleware('check.permission:admin.staff');
            });

            Route::group([
                'prefix' => 'timekeeping',
            ], function () {
                Route::get('/', [TimekeepingController::class, 'get'])->middleware('check.permission:admin.hr.staff');
                Route::post('/addMutilple', [TimekeepingController::class, 'addWorkingTimeForMultipleUser'])->middleware('check.permission:admin.hr');
                Route::post('/addNote', [TimekeepingController::class, 'addNoteForUser'])->middleware('check.permission:admin.hr');
                Route::get('/delete', [TimekeepingController::class, 'deleteNote'])->middleware('check.permission:admin.hr');
                Route::post('/update-cache-month', [TimekeepingController::class, 'updateCacheMonth'])->middleware('check.permission:admin');
                Route::post('/update-working-days', [TimekeepingController::class, 'saveWorkingDays'])->middleware('check.permission:admin.hr');
            });

            Route::group([
                'prefix' => 'tracking',
            ], function () {
                Route::post('/create', [TrackingController::class, 'create'])->middleware('check.permission:admin.hr');
                Route::post('/update', [TrackingController::class, 'update'])->middleware('check.permission:admin.hr');
                Route::get('/delete', [TrackingController::class, 'delete'])->middleware('check.permission:admin.hr');
            });

            Route::group([
                'prefix' => 'category',
            ], function () {
                Route::get('/get-list-master', [CategoryController::class, 'getListMaster']);
            });

            Route::group([
                'prefix' => 'leave-management',
            ], function () {
                Route::get('/', [LeaveManagementController::class, 'get'])->middleware('check.permission:admin.hr.staff');
                Route::post('/saveNoteLeave', [LeaveManagementController::class, 'saveNoteLeave'])->middleware('check.permission:admin.hr');
            });

            Route::group([
                'prefix' => 'ticket',
            ], function () {
                Route::get('/all', [TicketController::class, 'getAll'])->middleware('check.permission:admin.hr');
                Route::get('/getByUserId', [TicketController::class, 'getByUserId'])->middleware('check.permission:admin.hr.staff');
                Route::post('/create', [TicketController::class, 'createTicket'])->middleware('check.permission:admin.hr.staff');
                Route::get('/delete', [TicketController::class, 'deleteTicket'])->middleware('check.permission:admin.hr.staff');
                Route::post('/handle-ticket', [TicketController::class, 'handleTicket'])->middleware('check.permission:admin');
            });

            Route::group([
                'prefix' => 'criterias',
            ], function () {
                Route::get('/sprints/{sprintId}', [CriteriasController::class, 'getCriteriasForSprint'])->middleware('check.permission:admin');
                // Route::get('/users/{userId}', [CriteriasController::class, 'getCriteriasForUser'])->middleware('check.permission:admin');
                // Route::get('/users/{userId}/sprints/{sprintId}', [CriteriasController::class, 'getCriteriasForUserBySprint'])->middleware('check.permission:admin');
                Route::get('/getAll', [CriteriasController::class, 'getAllCriterias'])->middleware('check.permission:admin');
                Route::post('/sprints/{sprintId}', [CriteriasController::class, 'updateCriteriasForSprint'])->middleware('check.permission:admin');

                Route::get('/test-cases/getAll/{sprintId}', [TestCaseForSprintController::class, 'getAllReportsForSprint'])->middleware('check.permission:admin,tester');
                Route::post('/test-cases/{sprintId}', [TestCaseForSprintController::class, 'createTestReport'])->middleware('check.permission:admin,tester');
                Route::get('/test-cases/delete', [TestCaseForSprintController::class, 'deleteTestReport'])->middleware('check.permission:admin,tester');

                Route::get('/profiles-data', [ProfileController::class, 'getProfilesData'])->middleware('check.permission:admin.hr.staff.tester');
                Route::post('/profiles-data/update', [ProfileController::class, 'updateProfilesData'])->middleware('check.permission:admin.hr.staff.tester');
            });
        });
    });

Route::group([
    'prefix' => 'v1/admin/tracking',
], function () {
    Route::get('/', [TrackingController::class, 'get'])->middleware('check.permission:admin.hr.staff');
    Route::post('/scan-create', [TrackingController::class, 'create']);
    Route::post('/send-image', [TrackingController::class, 'saveImage']);
    // Route::get('/clear-cache', [SettingController::class, 'clearCache']);
});

Route::group([
    'prefix' => 'v1/admin/jira',
], function () {
    Route::get('/send-worklog-report', [JiraController::class, 'sendReport']);
});
