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

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import Any

from workos._types import _raise_deserialize_error
from workos.common.models.create_user_invite_options_locale import (
    CreateUserInviteOptionsLocale,
)


@dataclass(slots=True)
class CreateUserInviteOptions:
    """Create User Invite Options model."""

    email: str
    """The email address of the recipient."""
    organization_id: str | None = None
    """The ID of the [organization](https://workos.com/docs/reference/organization) that the recipient will join."""
    role_slug: str | None = None
    """The [role](https://workos.com/docs/authkit/roles) that the recipient will receive when they join the organization in the invitation."""
    expires_in_days: int | None = None
    """How many days the invitations will be valid for. Must be between 1 and 30 days. Defaults to 7 days if not specified."""
    inviter_user_id: str | None = None
    """The ID of the [user](https://workos.com/docs/reference/authkit/user) who invites the recipient. The invitation email will mention the name of this user."""
    locale: CreateUserInviteOptionsLocale | None = None
    """The locale to use when rendering the invitation email. See [supported locales](https://workos.com/docs/authkit/hosted-ui/localization)."""

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> CreateUserInviteOptions:
        """Deserialize from a dictionary."""
        try:
            return cls(
                email=data["email"],
                organization_id=data.get("organization_id"),
                role_slug=data.get("role_slug"),
                expires_in_days=data.get("expires_in_days"),
                inviter_user_id=data.get("inviter_user_id"),
                locale=CreateUserInviteOptionsLocale(_v_locale)
                if (_v_locale := data.get("locale")) is not None
                else None,
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("CreateUserInviteOptions", e)

    def to_dict(self) -> dict[str, Any]:
        """Serialize to a dictionary."""
        result: dict[str, Any] = {}
        result["email"] = self.email
        if self.organization_id is not None:
            result["organization_id"] = self.organization_id
        if self.role_slug is not None:
            result["role_slug"] = self.role_slug
        if self.expires_in_days is not None:
            result["expires_in_days"] = self.expires_in_days
        if self.inviter_user_id is not None:
            result["inviter_user_id"] = self.inviter_user_id
        if self.locale is not None:
            result["locale"] = (
                self.locale.value if isinstance(self.locale, Enum) else self.locale
            )
        return result
