from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Union
from datetime import datetime
from metorial.utils import parse_iso_datetime
import dataclasses


@dataclass
class ManagementInstanceSessionsConnectionsListOutputItemsMcpClient:
  object: str
  name: str
  version: str
  capabilities: Dict[str, Any]


@dataclass
class ManagementInstanceSessionsConnectionsListOutputItemsMcpServer:
  object: str
  name: str
  version: str
  capabilities: Dict[str, Any]


@dataclass
class ManagementInstanceSessionsConnectionsListOutputItemsMcp:
  object: str
  version: str
  connection_type: str
  client: Optional[ManagementInstanceSessionsConnectionsListOutputItemsMcpClient] = None
  server: Optional[ManagementInstanceSessionsConnectionsListOutputItemsMcpServer] = None


@dataclass
class ManagementInstanceSessionsConnectionsListOutputItemsUsage:
  total_productive_message_count: float
  total_productive_client_message_count: float
  total_productive_server_message_count: float


@dataclass
class ManagementInstanceSessionsConnectionsListOutputItemsServer:
  object: str
  id: str
  name: str
  type: str
  created_at: datetime
  updated_at: datetime
  description: Optional[str] = None


@dataclass
class ManagementInstanceSessionsConnectionsListOutputItemsSessionUsage:
  total_productive_message_count: float
  total_productive_client_message_count: float
  total_productive_server_message_count: float


@dataclass
class ManagementInstanceSessionsConnectionsListOutputItemsSession:
  object: str
  id: str
  status: str
  connection_status: str
  usage: ManagementInstanceSessionsConnectionsListOutputItemsSessionUsage
  metadata: Dict[str, Any]
  created_at: datetime
  updated_at: datetime


@dataclass
class ManagementInstanceSessionsConnectionsListOutputItemsServerDeploymentServer:
  object: str
  id: str
  name: str
  type: str
  created_at: datetime
  updated_at: datetime
  description: Optional[str] = None


@dataclass
class ManagementInstanceSessionsConnectionsListOutputItemsServerDeployment:
  object: str
  id: str
  metadata: Dict[str, Any]
  created_at: datetime
  updated_at: datetime
  server: ManagementInstanceSessionsConnectionsListOutputItemsServerDeploymentServer
  name: Optional[str] = None
  description: Optional[str] = None


@dataclass
class ManagementInstanceSessionsConnectionsListOutputItems:
  object: str
  id: str
  status: str
  mcp: ManagementInstanceSessionsConnectionsListOutputItemsMcp
  usage: ManagementInstanceSessionsConnectionsListOutputItemsUsage
  server: ManagementInstanceSessionsConnectionsListOutputItemsServer
  session: ManagementInstanceSessionsConnectionsListOutputItemsSession
  server_deployment: ManagementInstanceSessionsConnectionsListOutputItemsServerDeployment
  created_at: datetime
  started_at: datetime
  ended_at: Optional[datetime] = None


@dataclass
class ManagementInstanceSessionsConnectionsListOutputPagination:
  has_more_before: bool
  has_more_after: bool


@dataclass
class ManagementInstanceSessionsConnectionsListOutput:
  items: List[ManagementInstanceSessionsConnectionsListOutputItems]
  pagination: ManagementInstanceSessionsConnectionsListOutputPagination


class mapManagementInstanceSessionsConnectionsListOutputItemsMcpClient:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutputItemsMcpClient:
    return ManagementInstanceSessionsConnectionsListOutputItemsMcpClient(
      object=data.get("object"),
      name=data.get("name"),
      version=data.get("version"),
      capabilities=data.get("capabilities"),
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceSessionsConnectionsListOutputItemsMcpClient,
      Dict[str, Any],
      None,
    ]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    return dataclasses.asdict(value)


class mapManagementInstanceSessionsConnectionsListOutputItemsMcpServer:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutputItemsMcpServer:
    return ManagementInstanceSessionsConnectionsListOutputItemsMcpServer(
      object=data.get("object"),
      name=data.get("name"),
      version=data.get("version"),
      capabilities=data.get("capabilities"),
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceSessionsConnectionsListOutputItemsMcpServer,
      Dict[str, Any],
      None,
    ]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    return dataclasses.asdict(value)


class mapManagementInstanceSessionsConnectionsListOutputItemsMcp:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutputItemsMcp:
    return ManagementInstanceSessionsConnectionsListOutputItemsMcp(
      object=data.get("object"),
      version=data.get("version"),
      connection_type=data.get("connection_type"),
      client=mapManagementInstanceSessionsConnectionsListOutputItemsMcpClient.from_dict(
        data.get("client")
      )
      if data.get("client")
      else None,
      server=mapManagementInstanceSessionsConnectionsListOutputItemsMcpServer.from_dict(
        data.get("server")
      )
      if data.get("server")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceSessionsConnectionsListOutputItemsMcp, Dict[str, Any], None
    ]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    return dataclasses.asdict(value)


class mapManagementInstanceSessionsConnectionsListOutputItemsUsage:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutputItemsUsage:
    return ManagementInstanceSessionsConnectionsListOutputItemsUsage(
      total_productive_message_count=data.get("total_productive_message_count"),
      total_productive_client_message_count=data.get(
        "total_productive_client_message_count"
      ),
      total_productive_server_message_count=data.get(
        "total_productive_server_message_count"
      ),
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceSessionsConnectionsListOutputItemsUsage, Dict[str, Any], None
    ]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    return dataclasses.asdict(value)


class mapManagementInstanceSessionsConnectionsListOutputItemsServer:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutputItemsServer:
    return ManagementInstanceSessionsConnectionsListOutputItemsServer(
      object=data.get("object"),
      id=data.get("id"),
      name=data.get("name"),
      description=data.get("description"),
      type=data.get("type"),
      created_at=parse_iso_datetime(data.get("created_at"))
      if data.get("created_at")
      else None,
      updated_at=parse_iso_datetime(data.get("updated_at"))
      if data.get("updated_at")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceSessionsConnectionsListOutputItemsServer, Dict[str, Any], None
    ]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    return dataclasses.asdict(value)


class mapManagementInstanceSessionsConnectionsListOutputItemsSessionUsage:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutputItemsSessionUsage:
    return ManagementInstanceSessionsConnectionsListOutputItemsSessionUsage(
      total_productive_message_count=data.get("total_productive_message_count"),
      total_productive_client_message_count=data.get(
        "total_productive_client_message_count"
      ),
      total_productive_server_message_count=data.get(
        "total_productive_server_message_count"
      ),
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceSessionsConnectionsListOutputItemsSessionUsage,
      Dict[str, Any],
      None,
    ]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    return dataclasses.asdict(value)


class mapManagementInstanceSessionsConnectionsListOutputItemsSession:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutputItemsSession:
    return ManagementInstanceSessionsConnectionsListOutputItemsSession(
      object=data.get("object"),
      id=data.get("id"),
      status=data.get("status"),
      connection_status=data.get("connection_status"),
      usage=mapManagementInstanceSessionsConnectionsListOutputItemsSessionUsage.from_dict(
        data.get("usage")
      )
      if data.get("usage")
      else None,
      metadata=data.get("metadata"),
      created_at=parse_iso_datetime(data.get("created_at"))
      if data.get("created_at")
      else None,
      updated_at=parse_iso_datetime(data.get("updated_at"))
      if data.get("updated_at")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceSessionsConnectionsListOutputItemsSession, Dict[str, Any], None
    ]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    return dataclasses.asdict(value)


class mapManagementInstanceSessionsConnectionsListOutputItemsServerDeploymentServer:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutputItemsServerDeploymentServer:
    return ManagementInstanceSessionsConnectionsListOutputItemsServerDeploymentServer(
      object=data.get("object"),
      id=data.get("id"),
      name=data.get("name"),
      description=data.get("description"),
      type=data.get("type"),
      created_at=parse_iso_datetime(data.get("created_at"))
      if data.get("created_at")
      else None,
      updated_at=parse_iso_datetime(data.get("updated_at"))
      if data.get("updated_at")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceSessionsConnectionsListOutputItemsServerDeploymentServer,
      Dict[str, Any],
      None,
    ]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    return dataclasses.asdict(value)


class mapManagementInstanceSessionsConnectionsListOutputItemsServerDeployment:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutputItemsServerDeployment:
    return ManagementInstanceSessionsConnectionsListOutputItemsServerDeployment(
      object=data.get("object"),
      id=data.get("id"),
      name=data.get("name"),
      description=data.get("description"),
      metadata=data.get("metadata"),
      created_at=parse_iso_datetime(data.get("created_at"))
      if data.get("created_at")
      else None,
      updated_at=parse_iso_datetime(data.get("updated_at"))
      if data.get("updated_at")
      else None,
      server=mapManagementInstanceSessionsConnectionsListOutputItemsServerDeploymentServer.from_dict(
        data.get("server")
      )
      if data.get("server")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceSessionsConnectionsListOutputItemsServerDeployment,
      Dict[str, Any],
      None,
    ]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    return dataclasses.asdict(value)


class mapManagementInstanceSessionsConnectionsListOutputItems:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutputItems:
    return ManagementInstanceSessionsConnectionsListOutputItems(
      object=data.get("object"),
      id=data.get("id"),
      status=data.get("status"),
      mcp=mapManagementInstanceSessionsConnectionsListOutputItemsMcp.from_dict(
        data.get("mcp")
      )
      if data.get("mcp")
      else None,
      usage=mapManagementInstanceSessionsConnectionsListOutputItemsUsage.from_dict(
        data.get("usage")
      )
      if data.get("usage")
      else None,
      server=mapManagementInstanceSessionsConnectionsListOutputItemsServer.from_dict(
        data.get("server")
      )
      if data.get("server")
      else None,
      session=mapManagementInstanceSessionsConnectionsListOutputItemsSession.from_dict(
        data.get("session")
      )
      if data.get("session")
      else None,
      server_deployment=mapManagementInstanceSessionsConnectionsListOutputItemsServerDeployment.from_dict(
        data.get("server_deployment")
      )
      if data.get("server_deployment")
      else None,
      created_at=parse_iso_datetime(data.get("created_at"))
      if data.get("created_at")
      else None,
      started_at=parse_iso_datetime(data.get("started_at"))
      if data.get("started_at")
      else None,
      ended_at=parse_iso_datetime(data.get("ended_at"))
      if data.get("ended_at")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceSessionsConnectionsListOutputItems, Dict[str, Any], None
    ]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    return dataclasses.asdict(value)


class mapManagementInstanceSessionsConnectionsListOutputPagination:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutputPagination:
    return ManagementInstanceSessionsConnectionsListOutputPagination(
      has_more_before=data.get("has_more_before"),
      has_more_after=data.get("has_more_after"),
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceSessionsConnectionsListOutputPagination, Dict[str, Any], None
    ]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    return dataclasses.asdict(value)


class mapManagementInstanceSessionsConnectionsListOutput:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceSessionsConnectionsListOutput:
    return ManagementInstanceSessionsConnectionsListOutput(
      items=[
        mapManagementInstanceSessionsConnectionsListOutputItems.from_dict(item)
        for item in data.get("items", [])
        if item
      ],
      pagination=mapManagementInstanceSessionsConnectionsListOutputPagination.from_dict(
        data.get("pagination")
      )
      if data.get("pagination")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[ManagementInstanceSessionsConnectionsListOutput, Dict[str, Any], None]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    # assume dataclass for generated models
    return dataclasses.asdict(value)


@dataclass
class ManagementInstanceSessionsConnectionsListQuery:
  limit: Optional[float] = None
  after: Optional[str] = None
  before: Optional[str] = None
  cursor: Optional[str] = None
  order: Optional[str] = None


class mapManagementInstanceSessionsConnectionsListQuery:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> ManagementInstanceSessionsConnectionsListQuery:
    return ManagementInstanceSessionsConnectionsListQuery(
      limit=data.get("limit"),
      after=data.get("after"),
      before=data.get("before"),
      cursor=data.get("cursor"),
      order=data.get("order"),
    )

  @staticmethod
  def to_dict(
    value: Union[ManagementInstanceSessionsConnectionsListQuery, Dict[str, Any], None]
  ) -> Optional[Dict[str, Any]]:
    if value is None:
      return None
    if isinstance(value, dict):
      return value
    # assume dataclass for generated models
    return dataclasses.asdict(value)
