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 DashboardInstanceSecretsListOutputItemsType:
  identifier: str
  name: str


@dataclass
class DashboardInstanceSecretsListOutputItems:
  object: str
  id: str
  status: str
  type: DashboardInstanceSecretsListOutputItemsType
  description: str
  metadata: Dict[str, Any]
  organization_id: str
  instance_id: str
  fingerprint: str
  created_at: datetime
  last_used_at: Optional[datetime] = None


@dataclass
class DashboardInstanceSecretsListOutputPagination:
  has_more_before: bool
  has_more_after: bool


@dataclass
class DashboardInstanceSecretsListOutput:
  items: List[DashboardInstanceSecretsListOutputItems]
  pagination: DashboardInstanceSecretsListOutputPagination


class mapDashboardInstanceSecretsListOutputItemsType:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceSecretsListOutputItemsType:
    return DashboardInstanceSecretsListOutputItemsType(
      identifier=data.get("identifier"), name=data.get("name")
    )

  @staticmethod
  def to_dict(
    value: Union[DashboardInstanceSecretsListOutputItemsType, 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 mapDashboardInstanceSecretsListOutputItems:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceSecretsListOutputItems:
    return DashboardInstanceSecretsListOutputItems(
      object=data.get("object"),
      id=data.get("id"),
      status=data.get("status"),
      type=mapDashboardInstanceSecretsListOutputItemsType.from_dict(data.get("type"))
      if data.get("type")
      else None,
      description=data.get("description"),
      metadata=data.get("metadata"),
      organization_id=data.get("organization_id"),
      instance_id=data.get("instance_id"),
      fingerprint=data.get("fingerprint"),
      last_used_at=parse_iso_datetime(data.get("last_used_at"))
      if data.get("last_used_at")
      else None,
      created_at=parse_iso_datetime(data.get("created_at"))
      if data.get("created_at")
      else None,
    )

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

  @staticmethod
  def to_dict(
    value: Union[DashboardInstanceSecretsListOutputPagination, 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 mapDashboardInstanceSecretsListOutput:
  @staticmethod
  def from_dict(data: Dict[str, Any]) -> DashboardInstanceSecretsListOutput:
    return DashboardInstanceSecretsListOutput(
      items=[
        mapDashboardInstanceSecretsListOutputItems.from_dict(item)
        for item in data.get("items", [])
        if item
      ],
      pagination=mapDashboardInstanceSecretsListOutputPagination.from_dict(
        data.get("pagination")
      )
      if data.get("pagination")
      else None,
    )

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


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

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