"""ActionBatchSensor 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 (
    CreateNetworkSensorAlertsProfileConditionsItem,
    CreateNetworkSensorAlertsProfileRecipients,
    CreateNetworkSensorAlertsProfileSchedule,
    CreateOrganizationActionBatchActionsItem,
    UpdateDeviceSensorRelationshipsLivestream,
    UpdateNetworkSensorAlertsProfileConditionsItem,
    UpdateNetworkSensorAlertsProfileRecipients,
    UpdateNetworkSensorAlertsProfileSchedule,
)
from meraki_client.types import (
    CreateDeviceSensorCommandOperation,
)


class ActionBatchSensor:
    """ActionBatchSensor class."""

    def __init__(self) -> None:
        pass

    def create_device_sensor_command(
        self, *, serial: str, operation: CreateDeviceSensorCommandOperation
    ) -> CreateOrganizationActionBatchActionsItem:
        """Sends a command to a sensor.

        [API documentation: createDeviceSensorCommand](https://developer.cisco.com/meraki/api-v1/#!create-device-sensor-command)

        Args:
            serial: Serial.
            operation: Operation to run on the sensor. 'enableDownstreamPower',
                'disableDownstreamPower', and 'cycleDownstreamPower' turn power on/off
                to the device that is connected downstream of an MT40 power monitor.
                'refreshData' causes an MT15 or MT40 device to upload its latest
                readings so that they are immediately available in the Dashboard API.

        """
        serial = urllib.parse.quote(str(serial), safe="")
        path = f"/devices/{serial}/sensor/commands"

        payload: dict[str, Any] = {}
        if operation is not None:
            payload["operation"] = operation

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

    def update_device_sensor_relationships(
        self, serial: str, *, livestream: UpdateDeviceSensorRelationshipsLivestream | None = None
    ) -> CreateOrganizationActionBatchActionsItem:
        """Assign one or more sensor roles to a given sensor or camera device.

        [API documentation: updateDeviceSensorRelationships](https://developer.cisco.com/meraki/api-v1/#!update-device-sensor-relationships)

        Args:
            serial: Serial.
            livestream: A role defined between an MT sensor and an MV camera that adds the camera's
                livestream to the sensor's details page. Snapshots from the camera will
                also appear in alert notifications that the sensor triggers.

        """
        serial = urllib.parse.quote(str(serial), safe="")
        path = f"/devices/{serial}/sensor/relationships"

        payload: dict[str, Any] = {}
        if livestream is not None:
            payload["livestream"] = livestream.model_dump(by_alias=True, exclude_none=True)

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

    def create_network_sensor_alerts_profile(
        self,
        *,
        network_id: str,
        name: str,
        conditions: list[CreateNetworkSensorAlertsProfileConditionsItem],
        schedule: CreateNetworkSensorAlertsProfileSchedule | None = None,
        recipients: CreateNetworkSensorAlertsProfileRecipients | None = None,
        serials: list[str] | None = None,
        include_sensor_url: bool | None = None,
        message: str | None = None,
    ) -> CreateOrganizationActionBatchActionsItem:
        """Creates a sensor alert profile for a network.

        [API documentation: createNetworkSensorAlertsProfile](https://developer.cisco.com/meraki/api-v1/#!create-network-sensor-alerts-profile)

        Args:
            network_id: Network ID.
            name: Name of the sensor alert profile.
            schedule: The sensor schedule to use with the alert profile.
            conditions: List of conditions that will cause the profile to send an alert.
            recipients: List of recipients that will receive the alert.
            serials: List of device serials assigned to this sensor alert profile.
            include_sensor_url: Include dashboard link to sensor in messages (default: true).
            message: A custom message that will appear in email and text message alerts.

        """
        network_id = urllib.parse.quote(str(network_id), safe="")
        path = f"/networks/{network_id}/sensor/alerts/profiles"

        payload: dict[str, Any] = {}
        if name is not None:
            payload["name"] = name
        if schedule is not None:
            payload["schedule"] = schedule.model_dump(by_alias=True, exclude_none=True)
        if conditions is not None:
            payload["conditions"] = [
                item.model_dump(by_alias=True, exclude_none=True) for item in conditions
            ]
        if recipients is not None:
            payload["recipients"] = recipients.model_dump(by_alias=True, exclude_none=True)
        if serials is not None:
            payload["serials"] = serials
        if include_sensor_url is not None:
            payload["includeSensorUrl"] = include_sensor_url
        if message is not None:
            payload["message"] = message

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

    def update_network_sensor_alerts_profile(
        self,
        *,
        network_id: str,
        id: str,
        name: str | None = None,
        schedule: UpdateNetworkSensorAlertsProfileSchedule | None = None,
        conditions: list[UpdateNetworkSensorAlertsProfileConditionsItem] | None = None,
        recipients: UpdateNetworkSensorAlertsProfileRecipients | None = None,
        serials: list[str] | None = None,
        include_sensor_url: bool | None = None,
        message: str | None = None,
    ) -> CreateOrganizationActionBatchActionsItem:
        """Updates a sensor alert profile for a network.

        [API documentation: updateNetworkSensorAlertsProfile](https://developer.cisco.com/meraki/api-v1/#!update-network-sensor-alerts-profile)

        Args:
            network_id: Network ID.
            id: ID.
            name: Name of the sensor alert profile.
            schedule: The sensor schedule to use with the alert profile.
            conditions: List of conditions that will cause the profile to send an alert.
            recipients: List of recipients that will receive the alert.
            serials: List of device serials assigned to this sensor alert profile.
            include_sensor_url: Include dashboard link to sensor in messages (default: true).
            message: A custom message that will appear in email and text message alerts.

        """
        network_id = urllib.parse.quote(str(network_id), safe="")
        id = urllib.parse.quote(str(id), safe="")
        path = f"/networks/{network_id}/sensor/alerts/profiles/{id}"

        payload: dict[str, Any] = {}
        if name is not None:
            payload["name"] = name
        if schedule is not None:
            payload["schedule"] = schedule.model_dump(by_alias=True, exclude_none=True)
        if conditions is not None:
            payload["conditions"] = [
                item.model_dump(by_alias=True, exclude_none=True) for item in conditions
            ]
        if recipients is not None:
            payload["recipients"] = recipients.model_dump(by_alias=True, exclude_none=True)
        if serials is not None:
            payload["serials"] = serials
        if include_sensor_url is not None:
            payload["includeSensorUrl"] = include_sensor_url
        if message is not None:
            payload["message"] = message

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

    def delete_network_sensor_alerts_profile(
        self, *, network_id: str, id: str
    ) -> CreateOrganizationActionBatchActionsItem:
        """Deletes a sensor alert profile from a network.

        [API documentation: deleteNetworkSensorAlertsProfile](https://developer.cisco.com/meraki/api-v1/#!delete-network-sensor-alerts-profile)

        Args:
            network_id: Network ID.
            id: ID.

        """
        network_id = urllib.parse.quote(str(network_id), safe="")
        id = urllib.parse.quote(str(id), safe="")
        path = f"/networks/{network_id}/sensor/alerts/profiles/{id}"

        return CreateOrganizationActionBatchActionsItem(
            resource=path,
            operation="destroy",
        )

    def update_network_sensor_mqtt_broker(
        self, *, network_id: str, mqtt_broker_id: str, enabled: bool
    ) -> CreateOrganizationActionBatchActionsItem:
        """Update the sensor settings of an MQTT broker.

        [API documentation: updateNetworkSensorMqttBroker](https://developer.cisco.com/meraki/api-v1/#!update-network-sensor-mqtt-broker)

        Args:
            network_id: Network ID.
            mqtt_broker_id: Mqtt broker ID.
            enabled: Set to true to enable MQTT broker for sensor network.

        """
        network_id = urllib.parse.quote(str(network_id), safe="")
        mqtt_broker_id = urllib.parse.quote(str(mqtt_broker_id), safe="")
        path = f"/networks/{network_id}/sensor/mqttBrokers/{mqtt_broker_id}"

        payload: dict[str, Any] = {}
        if enabled is not None:
            payload["enabled"] = enabled

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