<?php

use App\Http\Controllers\Api\ActualController;
use App\Http\Controllers\Api\AllocationController;
use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\CapacityController;
use App\Http\Controllers\Api\HolidayController;
use App\Http\Controllers\Api\ProjectController;
use App\Http\Controllers\Api\ProjectMonthPlanController;
use App\Http\Controllers\Api\PtoController;
use App\Http\Controllers\Api\ReportController;
use App\Http\Controllers\Api\RolesController;
use App\Http\Controllers\Api\TeamMemberController;
use App\Http\Controllers\Api\UtilizationController;
use App\Http\Middleware\JwtAuth;
use App\Http\Resources\UserResource;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| These routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group.
|
*/

Route::post('/auth/login', [AuthController::class, 'login']);
Route::post('/auth/refresh', [AuthController::class, 'refresh']);

Route::middleware(JwtAuth::class)->group(function () {
    Route::post('/auth/logout', [AuthController::class, 'logout']);

    Route::get('/user', function (\Illuminate\Http\Request $request) {
        return new UserResource($request->user());
    });

    // Team Members
    Route::apiResource('team-members', TeamMemberController::class);

    // Roles
    Route::get('/roles', [RolesController::class, 'index']);

    // Projects
    Route::get('projects/types', [ProjectController::class, 'types']);
    Route::get('projects/statuses', [ProjectController::class, 'statuses']);
    Route::apiResource('projects', ProjectController::class);
    Route::put('projects/{project}/status', [ProjectController::class, 'updateStatus']);
    Route::put('projects/{project}/estimate', [ProjectController::class, 'setEstimate']);
    Route::put('projects/{project}/forecast', [ProjectController::class, 'setForecast']);

    // Project Month Plans
    Route::get('/project-month-plans', [ProjectMonthPlanController::class, 'index']);
    Route::put('/project-month-plans/bulk', [ProjectMonthPlanController::class, 'bulkUpdate']);

    // Capacity
    Route::get('/capacity', [CapacityController::class, 'individual']);
    Route::get('/capacity/team', [CapacityController::class, 'team']);
    Route::get('/capacity/revenue', [CapacityController::class, 'revenue']);
    Route::post('/capacity/availability', [CapacityController::class, 'saveAvailability']);
    Route::post('/capacity/availability/batch', [CapacityController::class, 'batchUpdateAvailability']);

    // Holidays
    Route::get('/holidays', [HolidayController::class, 'index']);
    Route::post('/holidays', [HolidayController::class, 'store']);
    Route::delete('/holidays/{id}', [HolidayController::class, 'destroy']);

    // PTO
    Route::get('/ptos', [PtoController::class, 'index']);
    Route::post('/ptos', [PtoController::class, 'store']);
    Route::delete('/ptos/{id}', [PtoController::class, 'destroy']);
    Route::put('/ptos/{id}/approve', [PtoController::class, 'approve']);

    // Allocations
    Route::apiResource('actuals', ActualController::class);
    Route::apiResource('allocations', AllocationController::class);
    Route::post('/allocations/bulk', [AllocationController::class, 'bulkStore']);

    // Utilization
    Route::prefix('utilization')->group(function () {
        Route::get('/running', [UtilizationController::class, 'running']);
        Route::get('/overall', [UtilizationController::class, 'overall']);
        Route::get('/data', [UtilizationController::class, 'data']);
        Route::get('/team', [UtilizationController::class, 'team']);
        Route::get('/team-running', [UtilizationController::class, 'teamRunning']);
        Route::get('/trend', [UtilizationController::class, 'trend']);
    });

    // Reports
    Route::get('/reports/allocations', [ReportController::class, 'allocations']);
});
