<?php

declare(strict_types=1);

namespace App\Framework\Waf\ValueObjects;

use App\Framework\Core\ValueObjects\Timestamp;

/**
 * Session-specific context information
 */
final readonly class SessionContext
{
    public function __construct(
        public ?string    $sessionId = null,
        public ?string    $userId = null,
        public ?Timestamp $sessionStart = null,
        public ?string    $fingerprint = null,
        public bool       $isAuthenticated = false,
        public array      $roles = []
    ) {
    }

    public function toArray(): array
    {
        return array_filter([
            'session_id' => $this->sessionId ? substr($this->sessionId, 0, 8) . '...' : null, // Partial for privacy
            'user_id' => $this->userId,
            'session_start' => $this->sessionStart?->toIsoString(),
            'fingerprint' => $this->fingerprint ? substr($this->fingerprint, 0, 8) . '...' : null,
            'is_authenticated' => $this->isAuthenticated,
            'roles' => $this->roles,
        ], fn ($value) => $value !== null && $value !== []);
    }
}
