# 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, Dict, List, Optional
from workos._types import _raise_deserialize_error
from workos.common.models.generate_link_intent import GenerateLinkIntent


@dataclass(slots=True)
class GenerateLink:
    """Generate Link model."""

    organization: str
    """An [Organization](https://workos.com/docs/reference/organization) identifier."""
    return_url: Optional[str] = None
    """The URL to go to when an admin clicks on your logo in the Admin Portal. If not specified, the return URL configured on the [Redirects](https://dashboard.workos.com/redirects) page will be used."""
    success_url: Optional[str] = None
    """The URL to redirect the admin to when they finish setup. If not specified, the success URL configured on the [Redirects](https://dashboard.workos.com/redirects) page will be used."""
    intent: Optional["GenerateLinkIntent"] = None
    """
      The intent of the Admin Portal.
        - `sso` - Launch Admin Portal for creating SSO connections
        - `dsync` - Launch Admin Portal for creating Directory Sync connections
        - `audit_logs` - Launch Admin Portal for viewing Audit Logs
        - `log_streams` - Launch Admin Portal for creating Log Streams
        - `domain_verification` - Launch Admin Portal for Domain Verification
        - `certificate_renewal` - Launch Admin Portal for renewing SAML Certificates
        - `bring_your_own_key` - Launch Admin Portal for configuring Bring Your Own Key"""
    it_contact_emails: Optional[List[str]] = None
    """The email addresses of the IT contacts to grant access to the Admin Portal for the given organization. Accepts up to 20 emails."""

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "GenerateLink":
        """Deserialize from a dictionary."""
        try:
            return cls(
                organization=data["organization"],
                return_url=data.get("return_url"),
                success_url=data.get("success_url"),
                intent=GenerateLinkIntent(_v_intent)
                if (_v_intent := data.get("intent")) is not None
                else None,
                it_contact_emails=data.get("it_contact_emails"),
            )
        except (KeyError, ValueError) as e:
            _raise_deserialize_error("GenerateLink", e)

    def to_dict(self) -> Dict[str, Any]:
        """Serialize to a dictionary."""
        result: Dict[str, Any] = {}
        result["organization"] = self.organization
        if self.return_url is not None:
            result["return_url"] = self.return_url
        if self.success_url is not None:
            result["success_url"] = self.success_url
        if self.intent is not None:
            result["intent"] = (
                self.intent.value if isinstance(self.intent, Enum) else self.intent
            )
        if self.it_contact_emails is not None:
            result["it_contact_emails"] = self.it_contact_emails
        return result
