<?php

declare(strict_types=1);

namespace App\Domain\User;

use App\Domain\Auth\Role;
use DateTimeImmutable;

/**
 * Identity record for a UI user. Local-admin records have `subject=null`,
 * `email=null`, `isLocal=true`; OIDC records carry a non-null `subject`
 * (the OIDC `sub` claim) and `isLocal=false`.
 *
 * `disabledAt` is null while the user is active. Any non-null value flips
 * the row off: ImpersonationMiddleware refuses to rewrite the principal,
 * and `AuthController::upsertOidc` / `upsertLocal` refuse to recompute
 * role on disabled rows. SEC_REVIEW F11.
 */
final class User
{
    public function __construct(
        public readonly int $id,
        public readonly ?string $subject,
        public readonly ?string $email,
        public readonly ?string $displayName,
        public readonly Role $role,
        public readonly bool $isLocal,
        public readonly ?DateTimeImmutable $disabledAt = null,
    ) {
    }

    public function isDisabled(): bool
    {
        return $this->disabledAt !== null;
    }
}
