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

hub.exec.boto3.client.fms.associate_admin_account
hub.exec.boto3.client.fms.disassociate_admin_account
hub.exec.boto3.client.fms.get_admin_account
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, admin_account: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Sets the Firewall Manager administrator account. The account must be a member of the organization in
    Organizations whose resources you want to protect. Firewall Manager sets the permissions that allow the account
    to administer your Firewall Manager policies. The account that you associate with Firewall Manager is called the
    Firewall Manager administrator account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        admin_account(Text): The Amazon Web Services account ID to associate with Firewall Manager as the Firewall Manager
            administrator account. This must be an Organizations member account. For more information about
            Organizations, see Managing the Amazon Web Services Accounts in Your Organization.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Disassociates the account that has been set as the Firewall Manager administrator account. To set a different
    account as the administrator account, you must submit an AssociateAdminAccount request.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

