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

hub.exec.boto3.client.sdb.create_domain
hub.exec.boto3.client.sdb.delete_domain
hub.exec.boto3.client.sdb.list_domains
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, domain_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     The CreateDomain operation creates a new domain. The domain name should be unique among the domains associated
    with the Access Key ID provided in the request. The CreateDomain operation may take 10 or more seconds to
    complete.   The client can create up to 100 domains per account.   If the client requires additional domains, go
    to  http://aws.amazon.com/contact-us/simpledb-limit-request/.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_name(Text): The name of the domain to create. The name can range between 3 and 255 characters and can
            contain the following characters: a-z, A-Z, 0-9, '_', '-', and '.'.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, domain_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     The DeleteDomain operation deletes a domain. Any items (and their attributes) in the domain are deleted as
    well. The DeleteDomain operation might take 10 or more seconds to complete.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_name(Text): The name of the domain to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

