"""Basic tags + boundary visibility.

Shows a source tool that activates a tag and a boundary tool that becomes hidden
on subsequent turns when message_history is provided.
"""

import asyncio
from enum import Enum

from pydantic_ai import Agent
from pydantic_ai.models.test import TestModel

from rgltr import boundary, configure, tag
from rgltr.pydantic_ai import RegulatedAgent


class Tag(Enum):
    CUSTOMERS = "customers"


class Boundary(Enum):
    EXTERNAL = "external"


def _tool_names(model: TestModel) -> list[str]:
    params = model.last_model_request_parameters
    if params is None or params.function_tools is None:
        return []
    return [tool.name for tool in params.function_tools]


async def main() -> None:
    configure(boundaries={Boundary.EXTERNAL: True})

    model = TestModel(call_tools=["get_customer"])
    agent = Agent(model)

    @agent.tool_plain
    @tag(activates=[Tag.CUSTOMERS])
    async def get_customer(customer_id: int) -> str:
        return f"customer:{customer_id}"

    @agent.tool_plain
    @boundary(Boundary.EXTERNAL)
    async def post_to_slack(message: str) -> str:
        return message

    regulated = RegulatedAgent(agent, agent_id="basic")

    # TestModel is deterministic; use tool lists to see visibility changes.
    first = await regulated.run("hello")
    first_tools = _tool_names(model)
    print("first tools:", first_tools)
    print("first output:", first.output)

    second = await regulated.run("follow up", message_history=first.all_messages())
    second_tools = _tool_names(model)
    print("second tools:", second_tools)
    print("second output:", second.output)


if __name__ == "__main__":
    asyncio.run(main())
