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

hub.exec.boto3.client.config.delete_configuration_aggregator
hub.exec.boto3.client.config.describe_configuration_aggregators
hub.exec.boto3.client.config.put_configuration_aggregator
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, configuration_aggregator_name: Text, account_aggregation_sources: List = None, organization_aggregation_source: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates and updates the configuration aggregator with the selected source accounts and regions. The source
    account can be individual account(s) or an organization.  accountIds that are passed will be replaced with
    existing accounts. If you want to add additional accounts into the aggregator, call DescribeAggregator to get
    the previous accounts and then append new ones.  AWS Config should be enabled in source accounts and regions you
    want to aggregate. If your source type is an organization, you must be signed in to the management account or a
    registered delegated administrator and all the features must be enabled in your organization. If the caller is a
    management account, AWS Config calls EnableAwsServiceAccess API to enable integration between AWS Config and AWS
    Organizations. If the caller is a registered delegated administrator, AWS Config calls
    ListDelegatedAdministrators API to verify whether the caller is a valid delegated administrator. To register a
    delegated administrator, see Register a Delegated Administrator in the AWS Config developer guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        configuration_aggregator_name(Text): The name of the configuration aggregator.
        account_aggregation_sources(List, optional): A list of AccountAggregationSource object. Defaults to None.
        organization_aggregation_source(Dict, optional): An OrganizationAggregationSource object. Defaults to None.
        tags(List, optional): An array of tag object. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.config.configuration_aggregator.present:
                - name: value
                - configuration_aggregator_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.config.configuration_aggregator.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.config.describe_configuration_aggregators(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.config.put_configuration_aggregator(
                ctx,
                
                
                **{"ConfigurationAggregatorName": configuration_aggregator_name, "AccountAggregationSources": account_aggregation_sources, "OrganizationAggregationSource": organization_aggregation_source, "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.config.describe_configuration_aggregators(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, configuration_aggregator_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified configuration aggregator and the aggregated data associated with the aggregator.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        configuration_aggregator_name(Text): The name of the configuration aggregator.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

