<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\Auth\AuthController;
use App\Http\Controllers\Api\Admin\UserController as AdminUserController;
use App\Http\Controllers\Api\Admin\AttendanceController as AdminAttendanceController;
use App\Http\Controllers\Api\Admin\PermissionController as AdminPermissionController;
use App\Http\Controllers\Api\Admin\LocationController as AdminLocationController;
use App\Http\Controllers\Api\Admin\ReportController as AdminReportController;
use App\Http\Controllers\Api\Employee\AttendanceController as EmployeeAttendanceController;
use App\Http\Controllers\Api\Employee\PermissionController as EmployeePermissionController;
use App\Http\Controllers\Api\Employee\ProfileController as EmployeeProfileController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

Route::name('api.')->group(function () {
    Route::post('/login', [AuthController::class, 'login'])->name('login');
    Route::post('/register', [AuthController::class, 'register']);
    Route::get('/user-by-token/{token}', [AuthController::class, 'getUserByToken']);

    Route::middleware(['auth:sanctum'])->group(function () {
        Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
        Route::get('/profile', [AuthController::class, 'profile']);
        Route::post('/profile/update', [AuthController::class, 'updateProfile']);
        Route::post('/profile/password', [AuthController::class, 'changePassword']);

        // Admin
        Route::middleware(['admin'])->prefix('admin')->group(function () {
            Route::get('/users', [AdminUserController::class, 'index']);
            Route::post('/users', [AdminUserController::class, 'store']);
            Route::get('/users/{id}', [AdminUserController::class, 'show']);
            Route::put('/users/{id}', [AdminUserController::class, 'update']);
            Route::delete('/users/{id}', [AdminUserController::class, 'destroy']);
            Route::get('/users/{id}/reset-password', [AdminUserController::class, 'resetPassword']);

            Route::get('/attendances', [AdminAttendanceController::class, 'index']);
            Route::get('/attendances/{id}', [AdminAttendanceController::class, 'show']);
            Route::put('/attendances/{id}/approve', [AdminAttendanceController::class, 'approve']);
            Route::get('/attendances/data/statistics', [AdminAttendanceController::class, 'statistics']);


            Route::get('/permissions', [AdminPermissionController::class, 'index']);
            Route::get('/permissions/{id}', [AdminPermissionController::class, 'show']);
            Route::put('/permissions/{id}/approve', [AdminPermissionController::class, 'approve']);
            Route::get('/permissions/data/statistics', [AdminPermissionController::class, 'statistics']);

            Route::get('/locations', [AdminLocationController::class, 'index']);
            Route::post('/locations', [AdminLocationController::class, 'store']);
            Route::get('/locations/{id}', [AdminLocationController::class, 'show']);
            Route::put('/locations/{id}', [AdminLocationController::class, 'update']);
            Route::delete('/locations/{id}', [AdminLocationController::class, 'destroy']);

            Route::get('/reports/attendance', [AdminReportController::class, 'attendanceReport']);
            Route::get('/reports/permission', [AdminReportController::class, 'permissionReport']);
            Route::get('/reports/attendance/export/excel', [AdminReportController::class, 'exportAttendanceExcel']);
            Route::get('/reports/attendance/export/pdf', [AdminReportController::class, 'exportAttendancePdf']);
            Route::get('/reports/permission/export/excel', [AdminReportController::class, 'exportPermissionExcel']);
            Route::get('/reports/permission/export/pdf', [AdminReportController::class, 'exportPermissionPdf']);
            Route::get('/reports/dashboard', [AdminReportController::class, 'dashboard']);
        });

        // Employee
        Route::middleware(['employee'])->prefix('employee')->group(function () {
            Route::post('/attendance', [EmployeeAttendanceController::class, 'store']);
            Route::get('/attendance/history', [EmployeeAttendanceController::class, 'history']);
            Route::get('/attendance/today-status', [EmployeeAttendanceController::class, 'todayStatus']);
            Route::get('/attendance/area', [AdminAttendanceController::class, 'area']);
            Route::get('/attendance/areas', [EmployeeAttendanceController::class, 'areas']);
            Route::post('/permission', [EmployeePermissionController::class, 'store']);
            Route::get('/permission/history', [EmployeePermissionController::class, 'history']);
            Route::get('/permission/{id}', [EmployeePermissionController::class, 'show']);
            Route::put('/permission/{id}/cancel', [EmployeePermissionController::class, 'cancel']);
            Route::get('/permission/data/statistics', [EmployeePermissionController::class, 'statistics']);

            Route::get('/profile', [EmployeeProfileController::class, 'show']);
            Route::put('/profile', [EmployeeProfileController::class, 'update']);
            Route::put('/password', [EmployeeProfileController::class, 'changePassword']);
            Route::post('/profile/photo', [EmployeeProfileController::class, 'uploadPhoto']);
            Route::delete('/profile/photo', [EmployeeProfileController::class, 'deletePhoto']);

            Route::post('/attendance/check-location', [EmployeeAttendanceController::class, 'checkLocation']);
        });
    });
});
