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

hub.exec.boto3.client.codedeploy.deregister_on_premises_instance
hub.exec.boto3.client.codedeploy.get_on_premises_instance
hub.exec.boto3.client.codedeploy.list_on_premises_instances
hub.exec.boto3.client.codedeploy.register_on_premises_instance
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, instance_name: Text, iam_session_arn: Text = None, iam_user_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Registers an on-premises instance.  Only one IAM ARN (an IAM session ARN or IAM user ARN) is supported in the
    request. You cannot use both.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        instance_name(Text): The name of the on-premises instance to register.
        iam_session_arn(Text, optional): The ARN of the IAM session to associate with the on-premises instance. Defaults to None.
        iam_user_arn(Text, optional): The ARN of the IAM user to associate with the on-premises instance. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.codedeploy.register_on_premises_instance(
                ctx,
                
                
                **{"instanceName": instance_name, "iamSessionArn": iam_session_arn, "iamUserArn": iam_user_arn}
            )
            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.codedeploy.get_on_premises_instance(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, instance_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deregisters an on-premises instance.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        instance_name(Text): The name of the on-premises instance to deregister.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

