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

hub.exec.boto3.client.workmail.create_mobile_device_access_rule
hub.exec.boto3.client.workmail.delete_mobile_device_access_rule
hub.exec.boto3.client.workmail.list_mobile_device_access_rules
hub.exec.boto3.client.workmail.update_mobile_device_access_rule
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, organization_id: Text, effect: Text, description: Text = None, device_types: List = None, not_device_types: List = None, device_models: List = None, not_device_models: List = None, device_operating_systems: List = None, not_device_operating_systems: List = None, device_user_agents: List = None, not_device_user_agents: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new mobile device access rule for the specified Amazon WorkMail organization.

    Args:
        name(Text): The rule name.
        organization_id(Text): The Amazon WorkMail organization under which the rule will be created.
        description(Text, optional): The rule description. Defaults to None.
        effect(Text): The effect of the rule when it matches. Allowed values are ALLOW or DENY.
        device_types(List, optional): Device types that the rule will match. Defaults to None.
        not_device_types(List, optional): Device types that the rule will not match. All other device types will match. Defaults to None.
        device_models(List, optional): Device models that the rule will match. Defaults to None.
        not_device_models(List, optional): Device models that the rule will not match. All other device models will match. Defaults to None.
        device_operating_systems(List, optional): Device operating systems that the rule will match. Defaults to None.
        not_device_operating_systems(List, optional): Device operating systems that the rule will not match. All other device operating systems will
            match. Defaults to None.
        device_user_agents(List, optional): Device user agents that the rule will match. Defaults to None.
        not_device_user_agents(List, optional): Device user agents that the rule will not match. All other device user agents will match. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.workmail.mobile_device_access_rule.present:
                - name: value
                - organization_id: value
                - effect: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.workmail.mobile_device_access_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.workmail.list_mobile_device_access_rules(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.workmail.create_mobile_device_access_rule(
                ctx,
                
                ClientToken=name,
                **{"Name": name, "OrganizationId": organization_id, "Description": description, "Effect": effect, "DeviceTypes": device_types, "NotDeviceTypes": not_device_types, "DeviceModels": device_models, "NotDeviceModels": not_device_models, "DeviceOperatingSystems": device_operating_systems, "NotDeviceOperatingSystems": not_device_operating_systems, "DeviceUserAgents": device_user_agents, "NotDeviceUserAgents": not_device_user_agents}
            )
            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.workmail.list_mobile_device_access_rules(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, organization_id: Text, mobile_device_access_rule_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a mobile device access rule for the specified Amazon WorkMail organization.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        organization_id(Text): The Amazon WorkMail organization under which the rule will be deleted.
        mobile_device_access_rule_id(Text): The identifier of the rule to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.workmail.mobile_device_access_rule.absent:
                - name: value
                - organization_id: value
                - mobile_device_access_rule_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.workmail.mobile_device_access_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.workmail.list_mobile_device_access_rules(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.workmail.delete_mobile_device_access_rule(
                ctx,
                
                
                **{"OrganizationId": organization_id, "MobileDeviceAccessRuleId": mobile_device_access_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.workmail.list_mobile_device_access_rules(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

