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

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union

if TYPE_CHECKING:
    from .._client import AsyncWorkOSClient, WorkOSClient

from .._types import RequestOptions, enum_value
from .models import PortalLinkResponse
from workos.common.models.generate_link_intent import GenerateLinkIntent


class AdminPortal:
    """Admin Portal API resources."""

    def __init__(self, client: "WorkOSClient") -> None:
        self._client = client

    def generate_link(
        self,
        *,
        organization: str,
        return_url: Optional[str] = None,
        success_url: Optional[str] = None,
        intent: Optional[Union[GenerateLinkIntent, str]] = None,
        it_contact_emails: Optional[List[str]] = None,
        request_options: Optional[RequestOptions] = None,
    ) -> PortalLinkResponse:
        """Generate a Portal Link

        Generate a Portal Link scoped to an Organization.

        Args:
            return_url: 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: 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.
            organization: An [Organization](https://workos.com/docs/reference/organization) identifier.
            intent: 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: The email addresses of the IT contacts to grant access to the Admin Portal for the given organization. Accepts up to 20 emails.
            request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

        Returns:
            PortalLinkResponse

        Raises:
            BadRequestError: If the request is malformed (400).
            AuthorizationError: If the request is forbidden (403).
            NotFoundError: If the resource is not found (404).
            UnprocessableEntityError: If the request data is unprocessable (422).
            AuthenticationError: If the API key is invalid (401).
            RateLimitExceededError: If rate limited (429).
            ServerError: If the server returns a 5xx error.
        """
        body: Dict[str, Any] = {
            k: v
            for k, v in {
                "return_url": return_url,
                "success_url": success_url,
                "organization": organization,
                "intent": enum_value(intent) if intent is not None else None,
                "it_contact_emails": it_contact_emails,
            }.items()
            if v is not None
        }
        return self._client.request(
            method="post",
            path=("portal", "generate_link"),
            body=body,
            model=PortalLinkResponse,
            request_options=request_options,
        )


class AsyncAdminPortal:
    """Admin Portal API resources (async)."""

    def __init__(self, client: "AsyncWorkOSClient") -> None:
        self._client = client

    async def generate_link(
        self,
        *,
        organization: str,
        return_url: Optional[str] = None,
        success_url: Optional[str] = None,
        intent: Optional[Union[GenerateLinkIntent, str]] = None,
        it_contact_emails: Optional[List[str]] = None,
        request_options: Optional[RequestOptions] = None,
    ) -> PortalLinkResponse:
        """Generate a Portal Link

        Generate a Portal Link scoped to an Organization.

        Args:
            return_url: 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: 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.
            organization: An [Organization](https://workos.com/docs/reference/organization) identifier.
            intent: 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: The email addresses of the IT contacts to grant access to the Admin Portal for the given organization. Accepts up to 20 emails.
            request_options: Per-request options. Supports extra_headers, timeout, max_retries, and base_url override.

        Returns:
            PortalLinkResponse

        Raises:
            BadRequestError: If the request is malformed (400).
            AuthorizationError: If the request is forbidden (403).
            NotFoundError: If the resource is not found (404).
            UnprocessableEntityError: If the request data is unprocessable (422).
            AuthenticationError: If the API key is invalid (401).
            RateLimitExceededError: If rate limited (429).
            ServerError: If the server returns a 5xx error.
        """
        body: Dict[str, Any] = {
            k: v
            for k, v in {
                "return_url": return_url,
                "success_url": success_url,
                "organization": organization,
                "intent": enum_value(intent) if intent is not None else None,
                "it_contact_emails": it_contact_emails,
            }.items()
            if v is not None
        }
        return await self._client.request(
            method="post",
            path=("portal", "generate_link"),
            body=body,
            model=PortalLinkResponse,
            request_options=request_options,
        )
