# This file is auto-generated by oagen. Do not edit.

from __future__ import annotations

from dataclasses import dataclass
from typing import cast
from typing import Any, Dict, List, Optional
from workos._types import _raise_deserialize_error

from .organization_domain_data import OrganizationDomainData


@dataclass(slots=True)
class OrganizationInput:
    """Organization Input model."""

    name: str
    """The name of the organization."""
    allow_profiles_outside_organization: Optional[bool] = None
    """Whether the organization allows profiles from outside the organization to sign in."""
    domains: Optional[List[str]] = None
    """The domains associated with the organization. Deprecated in favor of `domain_data`."""
    domain_data: Optional[List["OrganizationDomainData"]] = None
    """The domains associated with the organization, including verification state."""
    metadata: Optional[Dict[str, str]] = None
    """Object containing [metadata](https://workos.com/docs/authkit/metadata) key/value pairs associated with the Organization."""
    external_id: Optional[str] = None
    """An external identifier for the Organization."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "OrganizationInput":
        """Deserialize from a dictionary."""
        try:
            return cls(
                name=data["name"],
                allow_profiles_outside_organization=data.get(
                    "allow_profiles_outside_organization"
                ),
                domains=data.get("domains"),
                domain_data=[
                    OrganizationDomainData.from_dict(cast(Dict[str, Any], item))
                    for item in cast(list[Any], _v_domain_data)
                ]
                if (_v_domain_data := data.get("domain_data")) is not None
                else None,
                metadata=data.get("metadata"),
                external_id=data.get("external_id"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("OrganizationInput", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["name"] = self.name
        if self.allow_profiles_outside_organization is not None:
            result["allow_profiles_outside_organization"] = (
                self.allow_profiles_outside_organization
            )
        if self.domains is not None:
            result["domains"] = self.domains
        if self.domain_data is not None:
            result["domain_data"] = [item.to_dict() for item in self.domain_data]
        if self.metadata is not None:
            result["metadata"] = self.metadata
        else:
            result["metadata"] = None
        if self.external_id is not None:
            result["external_id"] = self.external_id
        else:
            result["external_id"] = None
        return result
