"""
Autogenerated state module using `pop-create-idem <https://gitlab.com/saltstack/pop/pop-create-idem>`__

hub.exec.boto3.client.iot.attach_security_profile
hub.exec.boto3.client.iot.create_security_profile
hub.exec.boto3.client.iot.delete_security_profile
hub.exec.boto3.client.iot.describe_security_profile
hub.exec.boto3.client.iot.detach_security_profile
hub.exec.boto3.client.iot.list_security_profiles
hub.exec.boto3.client.iot.update_security_profile
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, security_profile_name: Text, security_profile_description: Text = None, behaviors: List = None, alert_targets: Dict = None, additional_metrics_to_retain: List = None, additional_metrics_to_retain_v2: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Device Defender security profile.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        security_profile_name(Text): The name you are giving to the security profile.
        security_profile_description(Text, optional): A description of the security profile. Defaults to None.
        behaviors(List, optional): Specifies the behaviors that, when violated by a device (thing), cause an alert. Defaults to None.
        alert_targets(Dict, optional): Specifies the destinations to which alerts are sent. (Alerts are always sent to the console.)
            Alerts are generated when a device (thing) violates a behavior. Defaults to None.
        additional_metrics_to_retain(List, optional):  Please use CreateSecurityProfileRequest$additionalMetricsToRetainV2 instead.  A list of metrics
            whose data is retained (stored). By default, data is retained for any metric used in the
            profile's behaviors, but it is also retained for any metric specified here. Can be used with
            custom metrics; cannot be used with dimensions. Defaults to None.
        additional_metrics_to_retain_v2(List, optional): A list of metrics whose data is retained (stored). By default, data is retained for any metric
            used in the profile's behaviors, but it is also retained for any metric specified here. Can be
            used with custom metrics; cannot be used with dimensions. Defaults to None.
        tags(List, optional): Metadata that can be used to manage the security profile. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iot.security_profile.present:
                - name: value
                - security_profile_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iot.security_profile.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    
    before = await hub.exec.boto3.client.iot.describe_security_profile(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_security_profile(
                ctx,
                
                
                **{"securityProfileName": security_profile_name, "securityProfileDescription": security_profile_description, "behaviors": behaviors, "alertTargets": alert_targets, "additionalMetricsToRetain": additional_metrics_to_retain, "additionalMetricsToRetainV2": additional_metrics_to_retain_v2, "tags": tags}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            ret["comment"] = f"Created '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    
    # TODO perform other modifications as needed here
    ...

    after = await hub.exec.boto3.client.iot.describe_security_profile(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, security_profile_name: Text, expected_version: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a Device Defender security profile.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        security_profile_name(Text): The name of the security profile to be deleted.
        expected_version(int, optional): The expected version of the security profile. A new version is generated whenever the security
            profile is updated. If you specify a value that is different from the actual version, a
            VersionConflictException is thrown. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.iot.security_profile.absent:
                - name: value
                - security_profile_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iot.security_profile.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    

    before = await hub.exec.boto3.client.iot.describe_security_profile(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.delete_security_profile(
                ctx,
                
                
                **{"securityProfileName": security_profile_name, "expectedVersion": expected_version}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            result["comment"] = f"Deleted '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    

    after = await hub.exec.boto3.client.iot.describe_security_profile(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

