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

hub.exec.boto3.client.mq.create_broker
hub.exec.boto3.client.mq.delete_broker
hub.exec.boto3.client.mq.describe_broker
hub.exec.boto3.client.mq.list_brokers
hub.exec.boto3.client.mq.reboot_broker
hub.exec.boto3.client.mq.update_broker
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, auto_minor_version_upgrade: bool, broker_name: Text, deployment_mode: Text, engine_type: Text, engine_version: Text, host_instance_type: Text, publicly_accessible: bool, users: List, authentication_strategy: Text = None, configuration: Dict = None, creator_request_id: Text = None, encryption_options: Dict = None, ldap_server_metadata: Dict = None, logs: Dict = None, maintenance_window_start_time: Dict = None, security_groups: List = None, storage_type: Text = None, subnet_ids: List = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a broker. Note: This API is asynchronous. To create a broker, you must either use the AmazonMQFullAccess
    IAM policy or include the following EC2 permissions in your IAM policy. ec2:CreateNetworkInterface This
    permission is required to allow Amazon MQ to create an elastic network interface (ENI) on behalf of your
    account. ec2:CreateNetworkInterfacePermission This permission is required to attach the ENI to the broker
    instance. ec2:DeleteNetworkInterface ec2:DeleteNetworkInterfacePermission ec2:DetachNetworkInterface
    ec2:DescribeInternetGateways ec2:DescribeNetworkInterfaces ec2:DescribeNetworkInterfacePermissions
    ec2:DescribeRouteTables ec2:DescribeSecurityGroups ec2:DescribeSubnets ec2:DescribeVpcs For more information,
    see Create an IAM User and Get Your AWS Credentials and Never Modify or Delete the Amazon MQ Elastic Network
    Interface in the Amazon MQ Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        authentication_strategy(Text, optional): Optional. The authentication strategy used to secure the broker. The default is SIMPLE. Defaults to None.
        auto_minor_version_upgrade(bool): Enables automatic upgrades to new minor versions for brokers, as new versions are released and
            supported by Amazon MQ. Automatic upgrades occur during the scheduled maintenance window of the
            broker or after a manual broker reboot. Set to true by default, if no value is specified.
        broker_name(Text): Required. The broker's name. This value must be unique in your AWS account, 1-50 characters
            long, must contain only letters, numbers, dashes, and underscores, and must not contain white
            spaces, brackets, wildcard characters, or special characters.
        configuration(Dict, optional): A list of information about the configuration. Defaults to None.
        creator_request_id(Text, optional): The unique ID that the requester receives for the created broker. Amazon MQ passes your ID with
            the API action. Note: We recommend using a Universally Unique Identifier (UUID) for the
            creatorRequestId. You may omit the creatorRequestId if your application doesn't require
            idempotency. Defaults to None.
        deployment_mode(Text): Required. The broker's deployment mode.
        encryption_options(Dict, optional): Encryption options for the broker. Does not apply to RabbitMQ brokers. Defaults to None.
        engine_type(Text): Required. The type of broker engine. Currently, Amazon MQ supports ACTIVEMQ and RABBITMQ.
        engine_version(Text): Required. The broker engine's version. For a list of supported engine versions, see Supported
            engines.
        host_instance_type(Text): Required. The broker's instance type.
        ldap_server_metadata(Dict, optional): Optional. The metadata of the LDAP server used to authenticate and authorize connections to the
            broker. Does not apply to RabbitMQ brokers. Defaults to None.
        logs(Dict, optional): Enables Amazon CloudWatch logging for brokers. Defaults to None.
        maintenance_window_start_time(Dict, optional): The parameters that determine the WeeklyStartTime. Defaults to None.
        publicly_accessible(bool): Enables connections from applications outside of the VPC that hosts the broker's subnets. Set to
            false by default, if no value is provided.
        security_groups(List, optional): The list of rules (1 minimum, 125 maximum) that authorize connections to brokers. Defaults to None.
        storage_type(Text, optional): The broker's storage type. Defaults to None.
        subnet_ids(List, optional): The list of groups that define which subnets and IP ranges the broker can use from different
            Availability Zones. If you specify more than one subnet, the subnets must be in different
            Availability Zones. Amazon MQ will not be able to create VPC endpoints for your broker with
            multiple subnets in the same Availability Zone. A SINGLE_INSTANCE deployment requires one subnet
            (for example, the default subnet). An ACTIVE_STANDBY_MULTI_AZ Amazon MQ for ActiveMQ deployment
            requires two subnets. A CLUSTER_MULTI_AZ Amazon MQ for RabbitMQ deployment has no subnet
            requirements when deployed with public accessibility. Deployment without public accessibility
            requires at least one subnet. If you specify subnets in a shared VPC for a RabbitMQ broker, the
            associated VPC to which the specified subnets belong must be owned by your AWS account. Amazon
            MQ will not be able to create VPC endpoints in VPCs that are not owned by your AWS account. Defaults to None.
        tags(Dict, optional): Create tags when creating the broker. Defaults to None.
        users(List): Required. The list of broker users (persons or applications) who can access queues and topics.
            This value can contain only alphanumeric characters, dashes, periods, underscores, and tildes (-
            . _ ~). This value must be 2-100 characters long. Amazon MQ for RabbitMQ When you create an
            Amazon MQ for RabbitMQ broker, one and only one administrative user is accepted and created when
            a broker is first provisioned. All subsequent broker users are created by making RabbitMQ API
            calls directly to brokers or via the RabbitMQ web console.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.mq.broker.present:
                - name: value
                - auto_minor_version_upgrade: value
                - broker_name: value
                - deployment_mode: value
                - engine_type: value
                - engine_version: value
                - host_instance_type: value
                - publicly_accessible: value
                - users: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.mq.broker.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.mq.describe_broker(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mq.create_broker(
                ctx,
                
                
                **{"AuthenticationStrategy": authentication_strategy, "AutoMinorVersionUpgrade": auto_minor_version_upgrade, "BrokerName": broker_name, "Configuration": configuration, "CreatorRequestId": creator_request_id, "DeploymentMode": deployment_mode, "EncryptionOptions": encryption_options, "EngineType": engine_type, "EngineVersion": engine_version, "HostInstanceType": host_instance_type, "LdapServerMetadata": ldap_server_metadata, "Logs": logs, "MaintenanceWindowStartTime": maintenance_window_start_time, "PubliclyAccessible": publicly_accessible, "SecurityGroups": security_groups, "StorageType": storage_type, "SubnetIds": subnet_ids, "Tags": tags, "Users": users}
            )
            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.mq.describe_broker(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, broker_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a broker. Note: This API is asynchronous.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        broker_id(Text): The unique ID that Amazon MQ generates for the broker.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

