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


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


@dataclass
class DashboardInstanceSessionsCreateOutputServerDeploymentsConnectionUrls:
  sse: str
  streamable_http: str


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


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


@dataclass
class DashboardInstanceSessionsCreateOutput:
  object: str
  id: str
  status: str
  connection_status: str
  client_secret: DashboardInstanceSessionsCreateOutputClientSecret
  server_deployments: List[DashboardInstanceSessionsCreateOutputServerDeployments]
  usage: DashboardInstanceSessionsCreateOutputUsage
  metadata: Dict[str, Any]
  created_at: datetime
  updated_at: datetime


class mapDashboardInstanceSessionsCreateOutputClientSecret:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceSessionsCreateOutputClientSecret:
    return DashboardInstanceSessionsCreateOutputClientSecret(
      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[
      DashboardInstanceSessionsCreateOutputClientSecret, 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 mapDashboardInstanceSessionsCreateOutputServerDeploymentsServer:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceSessionsCreateOutputServerDeploymentsServer:
    return DashboardInstanceSessionsCreateOutputServerDeploymentsServer(
      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[
      DashboardInstanceSessionsCreateOutputServerDeploymentsServer, 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 mapDashboardInstanceSessionsCreateOutputServerDeploymentsConnectionUrls:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceSessionsCreateOutputServerDeploymentsConnectionUrls:
    return DashboardInstanceSessionsCreateOutputServerDeploymentsConnectionUrls(
      sse=data.get("sse"), streamable_http=data.get("streamable_http")
    )

  @staticmethod
  def to_dict(
    value: Union[
      DashboardInstanceSessionsCreateOutputServerDeploymentsConnectionUrls,
      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 mapDashboardInstanceSessionsCreateOutputServerDeployments:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceSessionsCreateOutputServerDeployments:
    return DashboardInstanceSessionsCreateOutputServerDeployments(
      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=mapDashboardInstanceSessionsCreateOutputServerDeploymentsServer.from_dict(
        data.get("server")
      )
      if data.get("server")
      else None,
      connection_urls=mapDashboardInstanceSessionsCreateOutputServerDeploymentsConnectionUrls.from_dict(
        data.get("connection_urls")
      )
      if data.get("connection_urls")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[
      DashboardInstanceSessionsCreateOutputServerDeployments, 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 mapDashboardInstanceSessionsCreateOutputUsage:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceSessionsCreateOutputUsage:
    return DashboardInstanceSessionsCreateOutputUsage(
      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[DashboardInstanceSessionsCreateOutputUsage, 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 mapDashboardInstanceSessionsCreateOutput:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceSessionsCreateOutput:
    return DashboardInstanceSessionsCreateOutput(
      object=data.get("object"),
      id=data.get("id"),
      status=data.get("status"),
      connection_status=data.get("connection_status"),
      client_secret=mapDashboardInstanceSessionsCreateOutputClientSecret.from_dict(
        data.get("client_secret")
      )
      if data.get("client_secret")
      else None,
      server_deployments=[
        mapDashboardInstanceSessionsCreateOutputServerDeployments.from_dict(item)
        for item in data.get("server_deployments", [])
        if item
      ],
      usage=mapDashboardInstanceSessionsCreateOutputUsage.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[DashboardInstanceSessionsCreateOutput, 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 DashboardInstanceSessionsCreateBody:
  server_deployments: List[Union[Dict[str, Any], str]]


class mapDashboardInstanceSessionsCreateBody:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceSessionsCreateBody:
    return DashboardInstanceSessionsCreateBody(
      server_deployments=data.get("server_deployments", [])
    )

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