from __future__ import annotations


def test_new_task_id_is_deterministic_with_patches(monkeypatch):
    import argus.core.ids as ids

    class _FakeDatetime:
        @staticmethod
        def now():
            class _DT:
                def strftime(self, fmt: str) -> str:
                    assert fmt == "%Y%m%d-%H%M%S"
                    return "20250101-010203"

            return _DT()

    monkeypatch.setattr(ids, "datetime", _FakeDatetime)
    monkeypatch.setattr(ids.secrets, "token_hex", lambda n: "abcd")

    assert ids.new_task_id("ppo") == "mvp2-ppo-20250101-010203-abcd"


def test_new_task_id_includes_user_when_provided(monkeypatch):
    import argus.core.ids as ids

    class _FakeDatetime:
        @staticmethod
        def now():
            class _DT:
                def strftime(self, fmt: str) -> str:
                    assert fmt == "%Y%m%d-%H%M%S"
                    return "20250101-010203"

            return _DT()

    monkeypatch.setattr(ids, "datetime", _FakeDatetime)
    monkeypatch.setattr(ids.secrets, "token_hex", lambda n: "abcd")

    assert ids.new_task_id("ppo", user_id="Alice_01") == "mvp2-alice_01-ppo-20250101-010203-abcd"


def test_attempt_submission_id_format():
    from argus.core.ids import attempt_submission_id

    assert attempt_submission_id("t", 1) == "t--a01"
    assert attempt_submission_id("t", 12) == "t--a12"


def test_new_model_key_includes_user(monkeypatch):
    import argus.core.ids as ids

    class _FakeDatetime:
        @staticmethod
        def now():
            class _DT:
                def strftime(self, fmt: str) -> str:
                    assert fmt == "%Y%m%d-%H%M%S"
                    return "20250101-010203"

            return _DT()

    monkeypatch.setattr(ids, "datetime", _FakeDatetime)
    monkeypatch.setattr(ids.secrets, "token_hex", lambda n: "abcd")

    assert ids.new_model_key(user_id="Alice_01") == "mvp2-alice_01-serve-20250101-010203-abcd"


def test_new_model_key_requires_user_id():
    from argus.core.ids import new_model_key

    try:
        new_model_key(user_id="")
        assert False, "expected ValueError"
    except ValueError as e:
        assert "user_id is required" in str(e)
