"""Nac 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 (
    CreateOrganizationNacCertificatesAuthoritiesCrlResponse,
)

if TYPE_CHECKING:
    from meraki_client.aio._session import Session


class Nac:
    """Nac class."""

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

    async def create_organization_nac_certificates_authorities_crl(
        self, *, organization_id: str, ca_id: str, content: str, is_delta: bool
    ) -> CreateOrganizationNacCertificatesAuthoritiesCrlResponse | None:
        """Create a new CRL (either base or delta) for an existing CA.

        [API documentation: createOrganizationNacCertificatesAuthoritiesCrl](https://developer.cisco.com/meraki/api-v1/#!create-organization-nac-certificates-authorities-crl)

        Args:
            organization_id: Organization ID.
            ca_id: ID of the CRL issuer.
            content: CRL content in PEM format.
            is_delta: Whether it's a delta CRL or not.

        Returns:
            Successful operation.

        Example API response:
            ```json
            {
              "crlId": "1234",
              "data": [
                {
                  "serial": "121B0A22949BAD8B639B6987DC10326E",
                  "revocationDate": "2022-08-28T07:34:01Z",
                  "reason": "Key Compromise"
                }
              ],
              "isDelta": false,
              "caId": "12345",
              "createdAt": "2021-09-19T19:34:10Z",
              "lastUpdatedAt": "2021-09-26T20:34:10Z"
            }
            ```

        """
        organization_id = urllib.parse.quote(str(organization_id), safe="")
        path = f"/organizations/{organization_id}/nac/certificates/authorities/crls"

        payload = {}
        if ca_id is not None:
            payload["caId"] = ca_id
        if content is not None:
            payload["content"] = content
        if is_delta is not None:
            payload["isDelta"] = is_delta

        return await self._session.post(
            scope="nac",
            operation_id="createOrganizationNacCertificatesAuthoritiesCrl",
            path=path,
            json=payload,
            response_schema=CreateOrganizationNacCertificatesAuthoritiesCrlResponse,
        )
