"""IdGenerator 前缀与长度。"""

from __future__ import annotations

import re

from linksoul_agentsdk.id_generator import IdGenerator


_ID_LEN = IdGenerator.RANDOM_LENGTH


def _check_id(prefix: str, gen):
    a, b = gen(), gen()
    assert a.startswith(prefix)
    assert b.startswith(prefix)
    assert a != b  # 几乎不可能撞
    assert re.fullmatch(rf"{prefix}[A-Za-z0-9]{{{_ID_LEN}}}", a)
    assert len(a) == len(prefix) + _ID_LEN


def test_flow_id():
    _check_id("flow_", IdGenerator.generate_flow_id)


def test_event_id():
    _check_id("event_", IdGenerator.generate_event_id)


def test_item_id():
    _check_id("item_", IdGenerator.generate_item_id)


def test_signal_id():
    _check_id("signal_", IdGenerator.generate_signal_id)


def test_pull_id():
    _check_id("pull_", IdGenerator.generate_pull_id)
