"""Agent profile management — identity, ownership, and lifecycle."""

from __future__ import annotations

from typing import Any, Dict, Optional

from .._resource import AsyncResource, Resource


class AgentProfiles(Resource):
    """ARM: Agent profile CRUD + lifecycle transitions."""

    def list(self) -> Any:
        """List all agent profiles for the tenant."""
        return self._get("/v1/agent/profiles")

    def create(self, *, agent_id: str, **kwargs: Any) -> Any:
        """Create a new agent profile."""
        return self._post("/v1/agent/profiles", {"agentId": agent_id, **kwargs})

    def get(self, agent_id: str) -> Any:
        """Get an agent profile by agentId."""
        return self._get(f"/v1/agent/profiles/{agent_id}")

    def update(self, agent_id: str, **kwargs: Any) -> Any:
        """Update an agent profile."""
        return self._patch(f"/v1/agent/profiles/{agent_id}", kwargs)

    def me(self) -> Any:
        """Get the calling agent's own profile (requires mTLS or agent JWT)."""
        return self._get("/v1/agent/profiles/me")

    def transition(self, agent_id: str, state: str) -> Any:
        """Transition an agent's lifecycle state."""
        return self._patch(f"/v1/agent/profiles/lifecycle/{agent_id}", {"state": state})

    def delete(self, agent_id: str) -> Any:
        """Delete (archive) an agent profile."""
        return self._delete(f"/v1/agent/profiles/{agent_id}")


class AsyncAgentProfiles(AsyncResource):
    """Async ARM: Agent profile CRUD + lifecycle transitions."""

    async def list(self) -> Any:
        return await self._get("/v1/agent/profiles")

    async def create(self, *, agent_id: str, **kwargs: Any) -> Any:
        return await self._post("/v1/agent/profiles", {"agentId": agent_id, **kwargs})

    async def get(self, agent_id: str) -> Any:
        return await self._get(f"/v1/agent/profiles/{agent_id}")

    async def update(self, agent_id: str, **kwargs: Any) -> Any:
        return await self._patch(f"/v1/agent/profiles/{agent_id}", kwargs)

    async def me(self) -> Any:
        return await self._get("/v1/agent/profiles/me")

    async def transition(self, agent_id: str, state: str) -> Any:
        return await self._patch(f"/v1/agent/profiles/lifecycle/{agent_id}", {"state": state})

    async def delete(self, agent_id: str) -> Any:
        return await self._delete(f"/v1/agent/profiles/{agent_id}")
