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

hub.exec.boto3.client.auditmanager.deregister_organization_admin_account
hub.exec.boto3.client.auditmanager.get_organization_admin_account
hub.exec.boto3.client.auditmanager.register_organization_admin_account
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, admin_account_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Enables an account within the organization as the delegated administrator for Audit Manager.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        admin_account_id(Text):  The identifier for the specified delegated administrator account.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.auditmanager.register_organization_admin_account(
                ctx,
                
                
                **{"adminAccountId": admin_account_id}
            )
            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.auditmanager.get_organization_admin_account(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, admin_account_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes the specified member account as a delegated administrator for Audit Manager.   When you remove a
    delegated administrator from your Audit Manager settings, or when you deregister a delegated administrator from
    Organizations, you continue to have access to the evidence that you previously collected under that account.
    However, Audit Manager will stop collecting and attaching evidence to that delegated administrator account
    moving forward.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        admin_account_id(Text, optional):  The identifier for the specified administrator account. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

