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

hub.exec.boto3.client.inspector.create_assessment_template
hub.exec.boto3.client.inspector.delete_assessment_template
hub.exec.boto3.client.inspector.describe_assessment_templates
hub.exec.boto3.client.inspector.list_assessment_templates
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, assessment_target_arn: Text, assessment_template_name: Text, duration_in_seconds: int, rules_package_arns: List, user_attributes_for_findings: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an assessment template for the assessment target that is specified by the ARN of 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.

    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 for which you want to create the assessment
            template.
        assessment_template_name(Text): The user-defined name that identifies the assessment template that you want to create. You can
            create several assessment templates for an assessment target. The names of the assessment
            templates that correspond to a particular assessment target must be unique.
        duration_in_seconds(int): The duration of the assessment run in seconds.
        rules_package_arns(List): The ARNs that specify the rules packages that you want to attach to the assessment template.
        user_attributes_for_findings(List, optional): The user-defined attributes that are assigned to every finding that is generated by the
            assessment run that uses this assessment template. An attribute is a key and value pair (an
            Attribute object). Within an assessment template, each key must be unique. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.inspector.assessment_template.present:
                - name: value
                - assessment_target_arn: value
                - assessment_template_name: value
                - duration_in_seconds: value
                - rules_package_arns: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.inspector.assessment_template.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_templates(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.inspector.create_assessment_template(
                ctx,
                
                
                **{"assessmentTargetArn": assessment_target_arn, "assessmentTemplateName": assessment_template_name, "durationInSeconds": duration_in_seconds, "rulesPackageArns": rules_package_arns, "userAttributesForFindings": user_attributes_for_findings}
            )
            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_templates(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

