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

hub.exec.boto3.client.docdb.create_db_instance
hub.exec.boto3.client.docdb.delete_db_instance
hub.exec.boto3.client.docdb.describe_db_instances
hub.exec.boto3.client.docdb.modify_db_instance
hub.exec.boto3.client.docdb.reboot_db_instance
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, db_instance_identifier: Text, db_instance_class: Text, engine: Text, db_cluster_identifier: Text, availability_zone: Text = None, preferred_maintenance_window: Text = None, auto_minor_version_upgrade: bool = None, tags: List = None, promotion_tier: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new instance.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        db_instance_identifier(Text): The instance identifier. This parameter is stored as a lowercase string. Constraints:   Must
            contain from 1 to 63 letters, numbers, or hyphens.   The first character must be a letter.
            Cannot end with a hyphen or contain two consecutive hyphens.   Example: mydbinstance.
        db_instance_class(Text): The compute and memory capacity of the instance; for example, db.r5.large.
        engine(Text): The name of the database engine to be used for this instance. Valid value: docdb.
        availability_zone(Text, optional): The Amazon EC2 Availability Zone that the instance is created in.  Default: A random, system-
            chosen Availability Zone in the endpoint's Region. Example: us-east-1d. Defaults to None.
        preferred_maintenance_window(Text, optional): The time range each week during which system maintenance can occur, in Universal Coordinated
            Time (UTC).  Format: ddd:hh24:mi-ddd:hh24:mi  The default is a 30-minute window selected at
            random from an 8-hour block of time for each Region, occurring on a random day of the week.
            Valid days: Mon, Tue, Wed, Thu, Fri, Sat, Sun Constraints: Minimum 30-minute window. Defaults to None.
        auto_minor_version_upgrade(bool, optional): This parameter does not apply to Amazon DocumentDB. Amazon DocumentDB does not perform minor
            version upgrades regardless of the value set. Default: false. Defaults to None.
        tags(List, optional): The tags to be assigned to the instance. You can assign up to 10 tags to an instance. Defaults to None.
        db_cluster_identifier(Text): The identifier of the cluster that the instance will belong to.
        promotion_tier(int, optional): A value that specifies the order in which an Amazon DocumentDB replica is promoted to the
            primary instance after a failure of the existing primary instance. Default: 1 Valid values: 0-15. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.docdb.db_instance.present:
                - name: value
                - db_instance_identifier: value
                - db_instance_class: value
                - engine: value
                - db_cluster_identifier: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.docdb.db_instance.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.docdb.describe_db_instances(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.docdb.create_db_instance(
                ctx,
                
                
                **{"DBInstanceIdentifier": db_instance_identifier, "DBInstanceClass": db_instance_class, "Engine": engine, "AvailabilityZone": availability_zone, "PreferredMaintenanceWindow": preferred_maintenance_window, "AutoMinorVersionUpgrade": auto_minor_version_upgrade, "Tags": tags, "DBClusterIdentifier": db_cluster_identifier, "PromotionTier": promotion_tier}
            )
            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.docdb.describe_db_instances(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, db_instance_identifier: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a previously provisioned instance.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        db_instance_identifier(Text): The instance identifier for the instance to be deleted. This parameter isn't case sensitive.
            Constraints:   Must match the name of an existing instance.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

