<?php

use App\Http\Controllers\Api\TokenAuthController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PrintJobController;
use App\Http\Controllers\StampanteController;
use App\Http\Controllers\EndpointController;
use App\Http\Controllers\AttivitaController;

/*
|--------------------------------------------------------------------------
| Login API (Sanctum token) — pubblico, con rate limit
|--------------------------------------------------------------------------
| POST /api/auth/token
| Body JSON: { "email", "password", "device_name": "agent-cassa-1" }
| Risposta: { "token", "token_type": "Bearer", "user": { ... } }
|
| Richieste successive: Header Authorization: Bearer <token>
| Doc: https://laravel.com/docs/12.x/sanctum#api-token-authentication
*/

Route::post('/auth/token', [TokenAuthController::class, 'store'])
    ->middleware('throttle:10,1');

    Route::get('test', function(){
        return response()->json(['message' => 'Hello World' , 'status' => 'success', 'success' => true]);
    });
Route::middleware(['auth:sanctum'])->group(function () {
    Route::get('/user', [TokenAuthController::class, 'user']);
    Route::post('/auth/logout', [TokenAuthController::class, 'destroy']);

    /*
    | Qui aggiungerai le route JSON per agent (es. poll print job, ack stampa).
    | Non usare i controller DataTable web (PrintJobController::index restituisce HTML).
    */
    //Attività dell'account
    Route::get('/attivita/list', [AttivitaController::class, 'list_api']);
    Route::get('/endpoint', [EndpointController::class, 'index_api']);

    //registra Agent-endpoint-Python
    // Route::post('/endpoint/registra', [EndpointController::class, 'register']);
    // Route::post('/endpoint/stampanti/registra', [EndpointController::class, 'stampanti_register']);
    // Route::get('/endpoint/get-lavoro', [EndpointController::class, 'get_lavoro']);
    // Route::post('/endpoint/stampanti/esito-stampa', [EndpointController::class, 'esito_stampa']);

    //Registra endpoint con Product Key
});


//Middleware per le route dell'endpoint
Route::middleware(['endpoint-token'])->group(function () {
    Route::post('/endpoint/stampanti/registra', [EndpointController::class, 'stampanti_register']);
    Route::get('/endpoint/get-lavoro', [EndpointController::class, 'get_lavoro']);
    Route::post('/endpoint/stampanti/esito-stampa', [EndpointController::class, 'esito_stampa']);
});

Route::get('/endpoint/registra-product-key', [EndpointController::class, 'api_register_product_key'])->middleware('throttle:10,1');