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 DashboardInstanceCustomServersEventsListOutputItems:
  object: str
  id: str
  type: str
  message: str
  payload: Dict[str, Any]
  custom_server_id: str
  created_at: datetime
  custom_server_version_id: Optional[str] = None


@dataclass
class DashboardInstanceCustomServersEventsListOutputPagination:
  has_more_before: bool
  has_more_after: bool


@dataclass
class DashboardInstanceCustomServersEventsListOutput:
  items: List[DashboardInstanceCustomServersEventsListOutputItems]
  pagination: DashboardInstanceCustomServersEventsListOutputPagination


class mapDashboardInstanceCustomServersEventsListOutputItems:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceCustomServersEventsListOutputItems:
    return DashboardInstanceCustomServersEventsListOutputItems(
      object=data.get("object"),
      id=data.get("id"),
      type=data.get("type"),
      message=data.get("message"),
      payload=data.get("payload"),
      custom_server_id=data.get("custom_server_id"),
      custom_server_version_id=data.get("custom_server_version_id"),
      created_at=parse_iso_datetime(data.get("created_at"))
      if data.get("created_at")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[
      DashboardInstanceCustomServersEventsListOutputItems, 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 mapDashboardInstanceCustomServersEventsListOutputPagination:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceCustomServersEventsListOutputPagination:
    return DashboardInstanceCustomServersEventsListOutputPagination(
      has_more_before=data.get("has_more_before"),
      has_more_after=data.get("has_more_after"),
    )

  @staticmethod
  def to_dict(
    value: Union[
      DashboardInstanceCustomServersEventsListOutputPagination, 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 mapDashboardInstanceCustomServersEventsListOutput:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceCustomServersEventsListOutput:
    return DashboardInstanceCustomServersEventsListOutput(
      items=[
        mapDashboardInstanceCustomServersEventsListOutputItems.from_dict(item)
        for item in data.get("items", [])
        if item
      ],
      pagination=mapDashboardInstanceCustomServersEventsListOutputPagination.from_dict(
        data.get("pagination")
      )
      if data.get("pagination")
      else None,
    )

  @staticmethod
  def to_dict(
    value: Union[DashboardInstanceCustomServersEventsListOutput, 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 DashboardInstanceCustomServersEventsListQuery:
  limit: Optional[float] = None
  after: Optional[str] = None
  before: Optional[str] = None
  cursor: Optional[str] = None
  order: Optional[str] = None
  version_id: Optional[Union[str, List[str]]] = None


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

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