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 DashboardInstanceSessionsListOutputItemsClientSecret:
  object: str
  type: str
  id: str
  secret: str
  expires_at: datetime


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


@dataclass
class DashboardInstanceSessionsListOutputItemsServerDeploymentsConnectionUrls:
  sse: str
  streamable_http: str


@dataclass
class DashboardInstanceSessionsListOutputItemsServerDeployments:
  object: str
  id: str
  metadata: Dict[str, Any]
  created_at: datetime
  updated_at: datetime
  server: DashboardInstanceSessionsListOutputItemsServerDeploymentsServer
  connection_urls: DashboardInstanceSessionsListOutputItemsServerDeploymentsConnectionUrls
  name: Optional[str] = None
  oauth_session_id: Optional[str] = None
  description: Optional[str] = None


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


@dataclass
class DashboardInstanceSessionsListOutputItems:
  object: str
  id: str
  status: str
  connection_status: str
  client_secret: DashboardInstanceSessionsListOutputItemsClientSecret
  server_deployments: List[DashboardInstanceSessionsListOutputItemsServerDeployments]
  usage: DashboardInstanceSessionsListOutputItemsUsage
  metadata: Dict[str, Any]
  created_at: datetime
  updated_at: datetime


@dataclass
class DashboardInstanceSessionsListOutputPagination:
  has_more_before: bool
  has_more_after: bool


@dataclass
class DashboardInstanceSessionsListOutput:
  items: List[DashboardInstanceSessionsListOutputItems]
  pagination: DashboardInstanceSessionsListOutputPagination


class mapDashboardInstanceSessionsListOutputItemsClientSecret:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceSessionsListOutputItemsClientSecret:
    return DashboardInstanceSessionsListOutputItemsClientSecret(
      object=data.get("object"),
      type=data.get("type"),
      id=data.get("id"),
      secret=data.get("secret"),
      expires_at=parse_iso_datetime(data.get("expires_at"))
      if data.get("expires_at")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[
      DashboardInstanceSessionsListOutputItemsClientSecret, 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 mapDashboardInstanceSessionsListOutputItemsServerDeploymentsServer:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceSessionsListOutputItemsServerDeploymentsServer:
    return DashboardInstanceSessionsListOutputItemsServerDeploymentsServer(
      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[
      DashboardInstanceSessionsListOutputItemsServerDeploymentsServer,
      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 mapDashboardInstanceSessionsListOutputItemsServerDeploymentsConnectionUrls:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceSessionsListOutputItemsServerDeploymentsConnectionUrls:
    return DashboardInstanceSessionsListOutputItemsServerDeploymentsConnectionUrls(
      sse=data.get("sse"), streamable_http=data.get("streamable_http")
    )

  @staticmethod
  def to_dict(
    value: Union[
      DashboardInstanceSessionsListOutputItemsServerDeploymentsConnectionUrls,
      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 mapDashboardInstanceSessionsListOutputItemsServerDeployments:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceSessionsListOutputItemsServerDeployments:
    return DashboardInstanceSessionsListOutputItemsServerDeployments(
      object=data.get("object"),
      id=data.get("id"),
      name=data.get("name"),
      oauth_session_id=data.get("oauth_session_id"),
      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=mapDashboardInstanceSessionsListOutputItemsServerDeploymentsServer.from_dict(
        data.get("server")
      )
      if data.get("server")
      else None,
      connection_urls=mapDashboardInstanceSessionsListOutputItemsServerDeploymentsConnectionUrls.from_dict(
        data.get("connection_urls")
      )
      if data.get("connection_urls")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[
      DashboardInstanceSessionsListOutputItemsServerDeployments, 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 mapDashboardInstanceSessionsListOutputItemsUsage:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceSessionsListOutputItemsUsage:
    return DashboardInstanceSessionsListOutputItemsUsage(
      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[DashboardInstanceSessionsListOutputItemsUsage, 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 mapDashboardInstanceSessionsListOutputItems:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceSessionsListOutputItems:
    return DashboardInstanceSessionsListOutputItems(
      object=data.get("object"),
      id=data.get("id"),
      status=data.get("status"),
      connection_status=data.get("connection_status"),
      client_secret=mapDashboardInstanceSessionsListOutputItemsClientSecret.from_dict(
        data.get("client_secret")
      )
      if data.get("client_secret")
      else None,
      server_deployments=[
        mapDashboardInstanceSessionsListOutputItemsServerDeployments.from_dict(item)
        for item in data.get("server_deployments", [])
        if item
      ],
      usage=mapDashboardInstanceSessionsListOutputItemsUsage.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[DashboardInstanceSessionsListOutputItems, 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 mapDashboardInstanceSessionsListOutputPagination:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceSessionsListOutputPagination:
    return DashboardInstanceSessionsListOutputPagination(
      has_more_before=data.get("has_more_before"),
      has_more_after=data.get("has_more_after"),
    )

  @staticmethod
  def to_dict(
    value: Union[DashboardInstanceSessionsListOutputPagination, 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 mapDashboardInstanceSessionsListOutput:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceSessionsListOutput:
    return DashboardInstanceSessionsListOutput(
      items=[
        mapDashboardInstanceSessionsListOutputItems.from_dict(item)
        for item in data.get("items", [])
        if item
      ],
      pagination=mapDashboardInstanceSessionsListOutputPagination.from_dict(
        data.get("pagination")
      )
      if data.get("pagination")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[DashboardInstanceSessionsListOutput, 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 DashboardInstanceSessionsListQuery:
  limit: Optional[float] = None
  after: Optional[str] = None
  before: Optional[str] = None
  cursor: Optional[str] = None
  order: Optional[str] = None
  status: Optional[Union[str, List[str]]] = None
  server_id: Optional[Union[str, List[str]]] = None
  server_variant_id: Optional[Union[str, List[str]]] = None
  server_implementation_id: Optional[Union[str, List[str]]] = None
  server_deployment_id: Optional[Union[str, List[str]]] = None


class mapDashboardInstanceSessionsListQuery:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceSessionsListQuery:
    return DashboardInstanceSessionsListQuery(
      limit=data.get("limit"),
      after=data.get("after"),
      before=data.get("before"),
      cursor=data.get("cursor"),
      order=data.get("order"),
      status=data.get("status"),
      server_id=data.get("server_id"),
      server_variant_id=data.get("server_variant_id"),
      server_implementation_id=data.get("server_implementation_id"),
      server_deployment_id=data.get("server_deployment_id"),
    )

  @staticmethod
  def to_dict(
    value: Union[DashboardInstanceSessionsListQuery, 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)
