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

hub.exec.boto3.client.appstream.create_directory_config
hub.exec.boto3.client.appstream.delete_directory_config
hub.exec.boto3.client.appstream.describe_directory_configs
hub.exec.boto3.client.appstream.update_directory_config
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, directory_name: Text, organizational_unit_distinguished_names: List, service_account_credentials: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Directory Config object in AppStream 2.0. This object includes the configuration information required
    to join fleets and image builders to Microsoft Active Directory domains.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        directory_name(Text): The fully qualified name of the directory (for example, corp.example.com).
        organizational_unit_distinguished_names(List): The distinguished names of the organizational units for computer accounts.
        service_account_credentials(Dict, optional): The credentials for the service account used by the fleet or image builder to connect to the
            directory. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appstream.create_directory_config(
                ctx,
                
                
                **{"DirectoryName": directory_name, "OrganizationalUnitDistinguishedNames": organizational_unit_distinguished_names, "ServiceAccountCredentials": service_account_credentials}
            )
            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.appstream.describe_directory_configs(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, directory_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified Directory Config object from AppStream 2.0. This object includes the information required
    to join streaming instances to an Active Directory domain.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

