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 DashboardInstanceProviderOauthConnectionsCreateOutputProvider:
  id: str
  name: str
  url: str
  image_url: str


@dataclass
class DashboardInstanceProviderOauthConnectionsCreateOutput:
  object: str
  id: str
  status: str
  name: str
  metadata: Dict[str, Any]
  provider: DashboardInstanceProviderOauthConnectionsCreateOutputProvider
  config: Dict[str, Any]
  client_id: str
  instance_id: str
  created_at: datetime
  updated_at: datetime
  description: Optional[str] = None
  template_id: Optional[str] = None


class mapDashboardInstanceProviderOauthConnectionsCreateOutputProvider:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceProviderOauthConnectionsCreateOutputProvider:
    return DashboardInstanceProviderOauthConnectionsCreateOutputProvider(
      id=data.get("id"),
      name=data.get("name"),
      url=data.get("url"),
      image_url=data.get("image_url"),
    )

  @staticmethod
  def to_dict(
    value: Union[
      DashboardInstanceProviderOauthConnectionsCreateOutputProvider,
      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 mapDashboardInstanceProviderOauthConnectionsCreateOutput:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceProviderOauthConnectionsCreateOutput:
    return DashboardInstanceProviderOauthConnectionsCreateOutput(
      object=data.get("object"),
      id=data.get("id"),
      status=data.get("status"),
      name=data.get("name"),
      description=data.get("description"),
      metadata=data.get("metadata"),
      provider=mapDashboardInstanceProviderOauthConnectionsCreateOutputProvider.from_dict(
        data.get("provider")
      )
      if data.get("provider")
      else None,
      config=data.get("config"),
      client_id=data.get("client_id"),
      instance_id=data.get("instance_id"),
      template_id=data.get("template_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[
      DashboardInstanceProviderOauthConnectionsCreateOutput, 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 DashboardInstanceProviderOauthConnectionsCreateBody:
  config: Dict[str, Any]
  client_id: str
  client_secret: str
  scopes: List[str]
  name: Optional[str] = None
  description: Optional[str] = None
  discovery_url: Optional[str] = None
  metadata: Optional[Dict[str, Any]] = None


class mapDashboardInstanceProviderOauthConnectionsCreateBody:
  @staticmethod
  def from_dict(
    data: Dict[str, Any]
  ) -> DashboardInstanceProviderOauthConnectionsCreateBody:
    return DashboardInstanceProviderOauthConnectionsCreateBody(
      name=data.get("name"),
      description=data.get("description"),
      discovery_url=data.get("discovery_url"),
      config=data.get("config"),
      client_id=data.get("client_id"),
      client_secret=data.get("client_secret"),
      scopes=data.get("scopes", []),
      metadata=data.get("metadata"),
    )

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