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

hub.exec.boto3.client.chime.create_sip_rule
hub.exec.boto3.client.chime.delete_sip_rule
hub.exec.boto3.client.chime.get_sip_rule
hub.exec.boto3.client.chime.list_sip_rules
hub.exec.boto3.client.chime.update_sip_rule
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, trigger_type: Text, trigger_value: Text, target_applications: List, disabled: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a SIP rule which can be used to run a SIP media application as a target for a specific trigger type.

    Args:
        name(Text): The name of the SIP rule.
        trigger_type(Text): The type of trigger assigned to the SIP rule in TriggerValue, currently RequestUriHostname or
            ToPhoneNumber.
        trigger_value(Text): If TriggerType is RequestUriHostname, the value can be the outbound host name of an Amazon Chime
            Voice Connector. If TriggerType is ToPhoneNumber, the value can be a customer-owned phone number
            in the E164 format. The SipMediaApplication specified in the SipRule is triggered if the request
            URI in an incoming SIP request matches the RequestUriHostname, or if the To header in the
            incoming SIP request matches the ToPhoneNumber value.
        disabled(bool, optional): Enables or disables a rule. You must disable rules before you can delete them. Defaults to None.
        target_applications(List): List of SIP media applications with priority and AWS Region. Only one SIP application per AWS
            Region can be used.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.chime.sip_rule.present:
                - name: value
                - trigger_type: value
                - trigger_value: value
                - target_applications: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.chime.sip_rule.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.chime.get_sip_rule(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.chime.create_sip_rule(
                ctx,
                
                
                **{"Name": name, "TriggerType": trigger_type, "TriggerValue": trigger_value, "Disabled": disabled, "TargetApplications": target_applications}
            )
            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.chime.get_sip_rule(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, sip_rule_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a SIP rule. You must disable a SIP rule before you can delete it.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        sip_rule_id(Text): The SIP rule ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.chime.sip_rule.absent:
                - name: value
                - sip_rule_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.chime.sip_rule.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.chime.get_sip_rule(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.chime.delete_sip_rule(
                ctx,
                
                
                **{"SipRuleId": sip_rule_id}
            )
            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.chime.get_sip_rule(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

