"""Signs HelixtaHR-shaped tokens with a test secret, so tests never need the real one."""

import time
from typing import Any

import jwt

HELIXTAHR_ISSUER = "https://helixtahr.test/api/v1/login"
HELIXTAHR_SECRET = "test-helixtahr-secret-" + "0123456789abcdef" * 3

_MISSING = object()


def meeting_token(
    *,
    secret: str = HELIXTAHR_SECRET,
    algorithm: str = "HS256",
    **claims: Any,
) -> str:
    """A `meeting_jwt_token` like HelixtaHR's login returns.

    Pass a claim to change it, or `claim=MISSING` to leave it out.
    """
    now = int(time.time())
    payload: dict[str, Any] = {
        "iss": HELIXTAHR_ISSUER,
        "iat": now,
        "exp": now + 30 * 24 * 3600,
        "nbf": now,
        "jti": "test-jti",
        "sub": "674",
        "company_id": 26,
        "role_id": "5",
        "role_name": "manager",
        "user_type": "1",
        "company_name": "Test Company",
        "user_id": 674,
        "emp_no": "emp1",
        "name": "Test User",
        "token_type": "meeting",
    }
    payload.update(claims)
    payload = {key: value for key, value in payload.items() if value is not _MISSING}
    return jwt.encode(payload, secret if algorithm != "none" else None, algorithm=algorithm)


MISSING: Any = _MISSING
