"""ActionBatchCampusGateway API endpoints.

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

"""

import urllib.parse
from typing import Any

from meraki_client.schemas import (
    CreateNetworkCampusGatewayClusterDevicesItem,
    CreateNetworkCampusGatewayClusterNameservers,
    CreateNetworkCampusGatewayClusterPortChannelsItem,
    CreateNetworkCampusGatewayClusterTunnelsItem,
    CreateNetworkCampusGatewayClusterUplinksItem,
    CreateOrganizationActionBatchActionsItem,
    UpdateNetworkCampusGatewayClusterDevicesItem,
    UpdateNetworkCampusGatewayClusterNameservers,
    UpdateNetworkCampusGatewayClusterPortChannelsItem,
    UpdateNetworkCampusGatewayClusterTunnelsItem,
    UpdateNetworkCampusGatewayClusterUplinksItem,
)


class ActionBatchCampusGateway:
    """ActionBatchCampusGateway class."""

    def __init__(self) -> None:
        pass

    def create_network_campus_gateway_cluster(
        self,
        *,
        network_id: str,
        name: str,
        uplinks: list[CreateNetworkCampusGatewayClusterUplinksItem],
        tunnels: list[CreateNetworkCampusGatewayClusterTunnelsItem],
        nameservers: CreateNetworkCampusGatewayClusterNameservers,
        port_channels: list[CreateNetworkCampusGatewayClusterPortChannelsItem],
        devices: list[CreateNetworkCampusGatewayClusterDevicesItem] | None = None,
        notes: str | None = None,
    ) -> CreateOrganizationActionBatchActionsItem:
        """Create a cluster and add campus gateways to it.

        [API documentation: createNetworkCampusGatewayCluster](https://developer.cisco.com/meraki/api-v1/#!create-network-campus-gateway-cluster)

        Args:
            network_id: Network ID.
            name: Name of the new cluster.
            uplinks: Uplink interface settings of the cluster.
            tunnels: Tunnel interface settings of the cluster: Reuse uplink or specify tunnel
                interface.
            nameservers: Nameservers of the cluster.
            port_channels: Port channel settings of the cluster.
            devices: Devices to be added to the cluster.
            notes: Notes about cluster with max size of 511 characters allowed.

        """
        network_id = urllib.parse.quote(str(network_id), safe="")
        path = f"/networks/{network_id}/campusGateway/clusters"

        payload: dict[str, Any] = {}
        if name is not None:
            payload["name"] = name
        if uplinks is not None:
            payload["uplinks"] = [
                item.model_dump(by_alias=True, exclude_none=True) for item in uplinks
            ]
        if tunnels is not None:
            payload["tunnels"] = [
                item.model_dump(by_alias=True, exclude_none=True) for item in tunnels
            ]
        if nameservers is not None:
            payload["nameservers"] = nameservers.model_dump(by_alias=True, exclude_none=True)
        if port_channels is not None:
            payload["portChannels"] = [
                item.model_dump(by_alias=True, exclude_none=True) for item in port_channels
            ]
        if devices is not None:
            payload["devices"] = [
                item.model_dump(by_alias=True, exclude_none=True) for item in devices
            ]
        if notes is not None:
            payload["notes"] = notes

        return CreateOrganizationActionBatchActionsItem(
            resource=path,
            operation="create",
            body=payload,
        )

    def update_network_campus_gateway_cluster(
        self,
        *,
        network_id: str,
        cluster_id: str,
        name: str | None = None,
        uplinks: list[UpdateNetworkCampusGatewayClusterUplinksItem] | None = None,
        tunnels: list[UpdateNetworkCampusGatewayClusterTunnelsItem] | None = None,
        nameservers: UpdateNetworkCampusGatewayClusterNameservers | None = None,
        port_channels: list[UpdateNetworkCampusGatewayClusterPortChannelsItem] | None = None,
        devices: list[UpdateNetworkCampusGatewayClusterDevicesItem] | None = None,
        notes: str | None = None,
    ) -> CreateOrganizationActionBatchActionsItem:
        """Update a cluster and add/remove campus gateways to/from it.

        [API documentation: updateNetworkCampusGatewayCluster](https://developer.cisco.com/meraki/api-v1/#!update-network-campus-gateway-cluster)

        Args:
            network_id: Network ID.
            cluster_id: Cluster ID.
            name: Name of the cluster.
            uplinks: Uplink interface settings of the cluster.
            tunnels: Tunnel interface settings of the cluster: Reuse uplink or specify tunnel
                interface.
            nameservers: Nameservers of the cluster.
            port_channels: Port channel settings of the cluster.
            devices: Devices in the cluster.
            notes: Notes about cluster with max size of 511 characters allowed.

        """
        network_id = urllib.parse.quote(str(network_id), safe="")
        cluster_id = urllib.parse.quote(str(cluster_id), safe="")
        path = f"/networks/{network_id}/campusGateway/clusters/{cluster_id}"

        payload: dict[str, Any] = {}
        if name is not None:
            payload["name"] = name
        if uplinks is not None:
            payload["uplinks"] = [
                item.model_dump(by_alias=True, exclude_none=True) for item in uplinks
            ]
        if tunnels is not None:
            payload["tunnels"] = [
                item.model_dump(by_alias=True, exclude_none=True) for item in tunnels
            ]
        if nameservers is not None:
            payload["nameservers"] = nameservers.model_dump(by_alias=True, exclude_none=True)
        if port_channels is not None:
            payload["portChannels"] = [
                item.model_dump(by_alias=True, exclude_none=True) for item in port_channels
            ]
        if devices is not None:
            payload["devices"] = [
                item.model_dump(by_alias=True, exclude_none=True) for item in devices
            ]
        if notes is not None:
            payload["notes"] = notes

        return CreateOrganizationActionBatchActionsItem(
            resource=path,
            operation="update",
            body=payload,
        )
