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

hub.exec.boto3.client.inspector.create_assessment_target
hub.exec.boto3.client.inspector.delete_assessment_target
hub.exec.boto3.client.inspector.describe_assessment_targets
hub.exec.boto3.client.inspector.list_assessment_targets
hub.exec.boto3.client.inspector.update_assessment_target
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, assessment_target_name: Text, resource_group_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new assessment target using the ARN of the resource group that is generated by CreateResourceGroup. If
    resourceGroupArn is not specified, all EC2 instances in the current AWS account and region are included in the
    assessment target. If the service-linked role isn’t already registered, this action also creates and registers a
    service-linked role to grant Amazon Inspector access to AWS Services needed to perform security assessments. You
    can create up to 50 assessment targets per AWS account. You can run up to 500 concurrent agents per AWS account.
    For more information, see  Amazon Inspector Assessment Targets.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        assessment_target_name(Text): The user-defined name that identifies the assessment target that you want to create. The name
            must be unique within the AWS account.
        resource_group_arn(Text, optional): The ARN that specifies the resource group that is used to create the assessment target. If
            resourceGroupArn is not specified, all EC2 instances in the current AWS account and region are
            included in the assessment target. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.inspector.create_assessment_target(
                ctx,
                
                
                **{"assessmentTargetName": assessment_target_name, "resourceGroupArn": resource_group_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.inspector.describe_assessment_targets(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, assessment_target_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the assessment target that is specified by the ARN of the assessment target.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        assessment_target_arn(Text): The ARN that specifies the assessment target that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

