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

hub.exec.boto3.client.config.delete_conformance_pack
hub.exec.boto3.client.config.describe_conformance_packs
hub.exec.boto3.client.config.put_conformance_pack
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, conformance_pack_name: Text, template_s3_uri: Text = None, template_body: Text = None, delivery_s3_bucket: Text = None, delivery_s3_key_prefix: Text = None, conformance_pack_input_parameters: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates or updates a conformance pack. A conformance pack is a collection of AWS Config rules that can be easily
    deployed in an account and a region and across AWS Organization. This API creates a service linked role
    AWSServiceRoleForConfigConforms in your account. The service linked role is created only when the role does not
    exist in your account.   You must specify either the TemplateS3Uri or the TemplateBody parameter, but not both.
    If you provide both AWS Config uses the TemplateS3Uri parameter and ignores the TemplateBody parameter.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        conformance_pack_name(Text): Name of the conformance pack you want to create.
        template_s3_uri(Text, optional): Location of file containing the template body (s3://bucketname/prefix). The uri must point to
            the conformance pack template (max size: 300 KB) that is located in an Amazon S3 bucket in the
            same region as the conformance pack.   You must have access to read Amazon S3 bucket. Defaults to None.
        template_body(Text, optional): A string containing full conformance pack template body. Structure containing the template body
            with a minimum length of 1 byte and a maximum length of 51,200 bytes.  You can only use a YAML
            template with one resource type, that is, config rule and a remediation action. Defaults to None.
        delivery_s3_bucket(Text, optional): Amazon S3 bucket where AWS Config stores conformance pack templates.  This field is optional. Defaults to None.
        delivery_s3_key_prefix(Text, optional): The prefix for the Amazon S3 bucket.   This field is optional. Defaults to None.
        conformance_pack_input_parameters(List, optional): A list of ConformancePackInputParameter objects. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.config.put_conformance_pack(
                ctx,
                
                
                **{"ConformancePackName": conformance_pack_name, "TemplateS3Uri": template_s3_uri, "TemplateBody": template_body, "DeliveryS3Bucket": delivery_s3_bucket, "DeliveryS3KeyPrefix": delivery_s3_key_prefix, "ConformancePackInputParameters": conformance_pack_input_parameters}
            )
            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.config.describe_conformance_packs(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, conformance_pack_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified conformance pack and all the AWS Config rules, remediation actions, and all evaluation
    results within that conformance pack. AWS Config sets the conformance pack to DELETE_IN_PROGRESS until the
    deletion is complete. You cannot update a conformance pack while it is in this state.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        conformance_pack_name(Text): Name of the conformance pack you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

