<?php

declare(strict_types=1);

namespace App\Application\Examples;

use App\Framework\Attributes\Route;
use App\Framework\Http\Method;
use App\Framework\Router\Result\JsonResult;
use App\Framework\Router\ValueObjects\ParameterConstraints;
use App\Framework\Router\ValueObjects\RouteParameters;

final readonly class SimpleParameterExample
{
    /**
     * Beispiel: Type-safe Parameter-Zugriff
     * URL: /api/user/123?include=profile
     */
    #[Route(path: '/api/user/{id}', method: Method::GET)]
    public function getUserById(RouteParameters $params): JsonResult
    {
        // Type-safe Parameter-Zugriff ohne Constraints
        $userId = $params->getInt('id');
        $include = $params->getString('include', 'basic');

        return new JsonResult([
            'user_id' => $userId,
            'include' => $include,
            'all_params' => $params->all(),
        ]);
    }

    /**
     * Beispiel: Mit Parameter-Validation
     * URL: /api/posts?page=2&limit=10
     */
    #[Route(path: '/api/posts', method: Method::GET)]
    public function listPosts(RouteParameters $params): JsonResult
    {
        // Definiere Parameter-Constraints
        $constraints = ParameterConstraints::create()
            ->page('page')           // 1-9999, optional
            ->limit('limit', 10, 50); // 10 default, max 50

        // Validiere Parameter
        $validatedParams = $params->validate($constraints);

        return new JsonResult([
            'page' => $validatedParams->getInt('page', 1),
            'limit' => $validatedParams->getInt('limit', 10),
            'posts' => ['Example Post 1', 'Example Post 2'],
        ]);
    }
}
