"""Administered API endpoints.

This file is automatically @generated from the Meraki API specification.
Do not edit this file manually.

"""

from __future__ import annotations

import urllib.parse
from typing import TYPE_CHECKING

from meraki_client.schemas import (
    GenerateAdministeredIdentitiesMeApiKeysResponse,
    GetAdministeredIdentitiesMeApiKeysResponseItem,
    GetAdministeredIdentitiesMeResponse,
)

if TYPE_CHECKING:
    from meraki_client._session import PaginatedResponse, Session


class Administered:
    """Administered class."""

    def __init__(self, session: Session) -> None:
        self._session = session

    def get_administered_identities_me(self) -> GetAdministeredIdentitiesMeResponse:
        """Returns the identity of the current user.

        [API documentation: getAdministeredIdentitiesMe](https://developer.cisco.com/meraki/api-v1/#!get-administered-identities-me)

        Returns:
            Successful operation.

        Example API response:
            ```json
            {
              "name": "Miles Meraki",
              "email": "miles@meraki.com",
              "lastUsedDashboardAt": "2018-02-11T00:00:00.090210Z",
              "authentication": {
                "mode": "email",
                "api": {
                  "key": {
                    "created": true
                  }
                },
                "twoFactor": {
                  "enabled": false
                },
                "saml": {
                  "enabled": false
                }
              }
            }
            ```

        """
        path = f"/administered/identities/me"

        return self._session.get(
            scope="administered",
            operation_id="getAdministeredIdentitiesMe",
            path=path,
            response_schema=GetAdministeredIdentitiesMeResponse,
        )

    def get_administered_identities_me_api_keys(
        self,
    ) -> PaginatedResponse[GetAdministeredIdentitiesMeApiKeysResponseItem]:
        """List the non-sensitive metadata associated with the API keys that belong to the user.

        [API documentation: getAdministeredIdentitiesMeApiKeys](https://developer.cisco.com/meraki/api-v1/#!get-administered-identities-me-api-keys)

        Returns:
            Successful operation.

        Note:
            Returns a lazy PaginatedResponse
            that can be iterated or collected with `.collect()`.
            Page metadata is available on `.meta` and `.meta_pages`.

        Example API response:
            ```json
            [
              {
                "suffix": "da4f",
                "createdAt": "2018-02-11T00:00:00.090210Z"
              }
            ]
            ```

        """
        path = f"/administered/identities/me/api/keys"

        return self._session.get_pages(
            scope="administered",
            operation_id="getAdministeredIdentitiesMeApiKeys",
            path=path,
            item_schema=GetAdministeredIdentitiesMeApiKeysResponseItem,
        )

    def generate_administered_identities_me_api_keys(
        self,
    ) -> GenerateAdministeredIdentitiesMeApiKeysResponse:
        """Generates an API key for an identity.

        [API documentation: generateAdministeredIdentitiesMeApiKeys](https://developer.cisco.com/meraki/api-v1/#!generate-administered-identities-me-api-keys)

        Returns:
            Successful operation.

        Example API response:
            ```json
            {
              "key": "1284392014819"
            }
            ```

        """
        path = f"/administered/identities/me/api/keys/generate"

        return self._session.post(
            scope="administered",
            operation_id="generateAdministeredIdentitiesMeApiKeys",
            path=path,
            response_schema=GenerateAdministeredIdentitiesMeApiKeysResponse,
        )

    def revoke_administered_identities_me_api_keys(self, suffix: str) -> None:
        """Revokes an identity's API key, using the last four characters of the key.

        [API documentation: revokeAdministeredIdentitiesMeApiKeys](https://developer.cisco.com/meraki/api-v1/#!revoke-administered-identities-me-api-keys)

        Args:
            suffix: Suffix.

        Returns:
            Successful operation.

        """
        suffix = urllib.parse.quote(str(suffix), safe="")
        path = f"/administered/identities/me/api/keys/{suffix}/revoke"

        return self._session.post(
            scope="administered", operation_id="revokeAdministeredIdentitiesMeApiKeys", path=path
        )
