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

hub.exec.boto3.client.ds.connect_directory
hub.exec.boto3.client.ds.create_directory
hub.exec.boto3.client.ds.delete_directory
hub.exec.boto3.client.ds.describe_directories
hub.exec.boto3.client.ds.share_directory
hub.exec.boto3.client.ds.unshare_directory
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, password: Text, size: Text, short_name: Text = None, description: Text = None, vpc_settings: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Simple AD directory. For more information, see Simple Active Directory in the Directory Service Admin
    Guide. Before you call CreateDirectory, ensure that all of the required permissions have been explicitly granted
    through a policy. For details about what permissions are required to run the CreateDirectory operation, see
    Directory Service API Permissions: Actions, Resources, and Conditions Reference.

    Args:
        name(Text): The fully qualified name for the directory, such as corp.example.com.
        short_name(Text, optional): The NetBIOS name of the directory, such as CORP. Defaults to None.
        password(Text): The password for the directory administrator. The directory creation process creates a directory
            administrator account with the user name Administrator and this password. If you need to change
            the password for the administrator account, you can use the ResetUserPassword API call. The
            regex pattern for this string is made up of the following conditions:   Length (?=^.{8,64}$) –
            Must be between 8 and 64 characters   AND any 3 of the following password complexity rules
            required by Active Directory:   Numbers and upper case and lowercase
            (?=.*\d)(?=.*[A-Z])(?=.*[a-z])   Numbers and special characters and lower case
            (?=.*\d)(?=.*[^A-Za-z0-9\s])(?=.*[a-z])   Special characters and upper case and lower case
            (?=.*[^A-Za-z0-9\s])(?=.*[A-Z])(?=.*[a-z])   Numbers and upper case and special characters
            (?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9\s])   For additional information about how Active Directory
            passwords are enforced, see Password must meet complexity requirements on the Microsoft website.
        description(Text, optional): A description for the directory. Defaults to None.
        size(Text): The size of the directory.
        vpc_settings(Dict, optional): A DirectoryVpcSettings object that contains additional information for the operation. Defaults to None.
        tags(List, optional): The tags to be assigned to the Simple AD directory. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ds.create_directory(
                ctx,
                
                
                **{"Name": name, "ShortName": short_name, "Password": password, "Description": description, "Size": size, "VpcSettings": vpc_settings, "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.ds.describe_directories(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, directory_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an Directory Service directory. Before you call DeleteDirectory, ensure that all of the required
    permissions have been explicitly granted through a policy. For details about what permissions are required to
    run the DeleteDirectory operation, see Directory Service API Permissions: Actions, Resources, and Conditions
    Reference.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

