from typing import Any, Dict, List, Optional, Union
from metorial_util_endpoint import BaseMetorialEndpoint, MetorialEndpointManager, MetorialRequest
from ..resources import mapDashboardInstancePortalsListOutput, DashboardInstancePortalsListOutput, mapDashboardInstancePortalsListQuery, DashboardInstancePortalsListQuery, mapDashboardInstancePortalsGetOutput, DashboardInstancePortalsGetOutput, mapDashboardInstancePortalsCreateOutput, DashboardInstancePortalsCreateOutput, mapDashboardInstancePortalsCreateBody, DashboardInstancePortalsCreateBody, mapDashboardInstancePortalsUpdateOutput, DashboardInstancePortalsUpdateOutput, mapDashboardInstancePortalsUpdateBody, DashboardInstancePortalsUpdateBody, mapDashboardInstancePortalsDeleteOutput, DashboardInstancePortalsDeleteOutput

class MetorialPortalsEndpoint(BaseMetorialEndpoint):
    """Use Portals to create custom branded MCP server marketplaces for your organization."""

    def __init__(self, config: MetorialEndpointManager):
        super().__init__(config)

    def list(self, *, limit: Optional[float] = None, after: Optional[str] = None, before: Optional[str] = None, cursor: Optional[str] = None, order: Optional[str] = None) -> DashboardInstancePortalsListOutput:
        """
    List portals
    Returns a paginated list of portals.

    :param limit: Optional[float] (optional)
    :param after: Optional[str] (optional)
    :param before: Optional[str] (optional)
    :param cursor: Optional[str] (optional)
    :param order: Optional[str] (optional)
    :return: DashboardInstancePortalsListOutput
    """
        # Build query parameters from keyword arguments
        query_dict = {}
        if limit is not None:
            query_dict["limit"] = limit
        if after is not None:
            query_dict["after"] = after
        if before is not None:
            query_dict["before"] = before
        if cursor is not None:
            query_dict["cursor"] = cursor
        if order is not None:
            query_dict["order"] = order

        request = MetorialRequest(
            path=['portals'],
            query=query_dict
        )
        return self._get(request).transform(mapDashboardInstancePortalsListOutput.from_dict)

    def get(self, portal_id: str) -> DashboardInstancePortalsGetOutput:
        """
    Get portal
    Retrieves details for a specific portal.

    :param portal_id: str
    :return: DashboardInstancePortalsGetOutput
    """
        request = MetorialRequest(
            path=['portals', portal_id]
        )
        return self._get(request).transform(mapDashboardInstancePortalsGetOutput.from_dict)

    def create(self, *, name: str, description: Optional[str] = None, session_expiry_time_in_seconds: Optional[float] = None) -> DashboardInstancePortalsCreateOutput:
        """
    Create portal
    Creates a new portal for the instance.

    :param name: str
    :param description: Optional[str] (optional)
    :param session_expiry_time_in_seconds: Optional[float] (optional)
    :return: DashboardInstancePortalsCreateOutput
    """
        # Build body parameters from keyword arguments
        body_dict = {}
        body_dict["name"] = name
        if description is not None:
            body_dict["description"] = description
        if session_expiry_time_in_seconds is not None:
            body_dict["session_expiry_time_in_seconds"] = session_expiry_time_in_seconds

        request = MetorialRequest(
            path=['portals'],
            body=body_dict
        )
        return self._post(request).transform(mapDashboardInstancePortalsCreateOutput.from_dict)

    def update(self, portal_id: str, *, name: Optional[str] = None, description: Optional[str] = None, session_expiry_time_in_seconds: Optional[float] = None) -> DashboardInstancePortalsUpdateOutput:
        """
    Update portal
    Updates an existing portal for the instance.

    :param portal_id: str
    :param name: Optional[str] (optional)
    :param description: Optional[str] (optional)
    :param session_expiry_time_in_seconds: Optional[float] (optional)
    :return: DashboardInstancePortalsUpdateOutput
    """
        # Build body parameters from keyword arguments
        body_dict = {}
        if name is not None:
            body_dict["name"] = name
        if description is not None:
            body_dict["description"] = description
        if session_expiry_time_in_seconds is not None:
            body_dict["session_expiry_time_in_seconds"] = session_expiry_time_in_seconds

        request = MetorialRequest(
            path=['portals', portal_id],
            body=body_dict
        )
        return self._patch(request).transform(mapDashboardInstancePortalsUpdateOutput.from_dict)

    def delete(self, portal_id: str) -> DashboardInstancePortalsDeleteOutput:
        """
    Delete portal
    Archives a portal.

    :param portal_id: str
    :return: DashboardInstancePortalsDeleteOutput
    """
        request = MetorialRequest(
            path=['portals', portal_id]
        )
        return self._delete(request).transform(mapDashboardInstancePortalsDeleteOutput.from_dict)