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 ManagementInstanceCustomServersDeploymentsGetOutputCreatorActorTeams:
  id: str
  name: str
  slug: str
  assignment_id: str
  created_at: datetime
  updated_at: datetime


@dataclass
class ManagementInstanceCustomServersDeploymentsGetOutputCreatorActor:
  object: str
  id: str
  type: str
  organization_id: str
  name: str
  image_url: str
  teams: List[ManagementInstanceCustomServersDeploymentsGetOutputCreatorActorTeams]
  created_at: datetime
  updated_at: datetime
  email: Optional[str] = None


@dataclass
class ManagementInstanceCustomServersDeploymentsGetOutputStepsLogs:
  timestamp: datetime
  line: str
  type: str


@dataclass
class ManagementInstanceCustomServersDeploymentsGetOutputSteps:
  object: str
  id: str
  index: float
  status: str
  type: str
  logs: List[ManagementInstanceCustomServersDeploymentsGetOutputStepsLogs]
  created_at: datetime
  started_at: Optional[datetime] = None
  ended_at: Optional[datetime] = None


@dataclass
class ManagementInstanceCustomServersDeploymentsGetOutput:
  object: str
  id: str
  status: str
  trigger: str
  creator_actor: ManagementInstanceCustomServersDeploymentsGetOutputCreatorActor
  custom_server_id: str
  created_at: datetime
  updated_at: datetime
  steps: List[ManagementInstanceCustomServersDeploymentsGetOutputSteps]
  custom_server_version_id: Optional[str] = None
  started_at: Optional[datetime] = None
  ended_at: Optional[datetime] = None


class mapManagementInstanceCustomServersDeploymentsGetOutputCreatorActorTeams:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceCustomServersDeploymentsGetOutputCreatorActorTeams:
    return ManagementInstanceCustomServersDeploymentsGetOutputCreatorActorTeams(
      id=data.get("id"),
      name=data.get("name"),
      slug=data.get("slug"),
      assignment_id=data.get("assignment_id"),
      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[
      ManagementInstanceCustomServersDeploymentsGetOutputCreatorActorTeams,
      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 mapManagementInstanceCustomServersDeploymentsGetOutputCreatorActor:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceCustomServersDeploymentsGetOutputCreatorActor:
    return ManagementInstanceCustomServersDeploymentsGetOutputCreatorActor(
      object=data.get("object"),
      id=data.get("id"),
      type=data.get("type"),
      organization_id=data.get("organization_id"),
      name=data.get("name"),
      email=data.get("email"),
      image_url=data.get("image_url"),
      teams=[
        mapManagementInstanceCustomServersDeploymentsGetOutputCreatorActorTeams.from_dict(
          item
        )
        for item in data.get("teams", [])
        if item
      ],
      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[
      ManagementInstanceCustomServersDeploymentsGetOutputCreatorActor,
      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 mapManagementInstanceCustomServersDeploymentsGetOutputStepsLogs:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceCustomServersDeploymentsGetOutputStepsLogs:
    return ManagementInstanceCustomServersDeploymentsGetOutputStepsLogs(
      timestamp=parse_iso_datetime(data.get("timestamp"))
      if data.get("timestamp")
      else None,
      line=data.get("line"),
      type=data.get("type"),
    )

  @staticmethod
  def to_dict(
    value: Union[
      ManagementInstanceCustomServersDeploymentsGetOutputStepsLogs, 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 mapManagementInstanceCustomServersDeploymentsGetOutputSteps:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceCustomServersDeploymentsGetOutputSteps:
    return ManagementInstanceCustomServersDeploymentsGetOutputSteps(
      object=data.get("object"),
      id=data.get("id"),
      index=data.get("index"),
      status=data.get("status"),
      type=data.get("type"),
      logs=[
        mapManagementInstanceCustomServersDeploymentsGetOutputStepsLogs.from_dict(item)
        for item in data.get("logs", [])
        if item
      ],
      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[
      ManagementInstanceCustomServersDeploymentsGetOutputSteps, 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 mapManagementInstanceCustomServersDeploymentsGetOutput:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> ManagementInstanceCustomServersDeploymentsGetOutput:
    return ManagementInstanceCustomServersDeploymentsGetOutput(
      object=data.get("object"),
      id=data.get("id"),
      status=data.get("status"),
      trigger=data.get("trigger"),
      creator_actor=mapManagementInstanceCustomServersDeploymentsGetOutputCreatorActor.from_dict(
        data.get("creator_actor")
      )
      if data.get("creator_actor")
      else None,
      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,
      updated_at=parse_iso_datetime(data.get("updated_at"))
      if data.get("updated_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,
      steps=[
        mapManagementInstanceCustomServersDeploymentsGetOutputSteps.from_dict(item)
        for item in data.get("steps", [])
        if item
      ],
    )

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