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

hub.exec.boto3.client.config.delete_organization_conformance_pack
hub.exec.boto3.client.config.describe_organization_conformance_packs
hub.exec.boto3.client.config.put_organization_conformance_pack
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, organization_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, excluded_accounts: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deploys conformance packs across member accounts in an AWS Organization. Only a master account and a delegated
    administrator can call this API. When calling this API with a delegated administrator, you must ensure AWS
    Organizations ListDelegatedAdministrator permissions are added. This API enables organization service access for
    config-multiaccountsetup.amazonaws.com through the EnableAWSServiceAccess action and creates a service linked
    role AWSServiceRoleForConfigMultiAccountSetup in the master or delegated administrator account of your
    organization. The service linked role is created only when the role does not exist in the caller account. To use
    this API with delegated administrator, register a delegated administrator by calling AWS Organization register-
    delegate-admin for config-multiaccountsetup.amazonaws.com.  Prerequisite: Ensure you call EnableAllFeatures API
    to enable all features in an organization. 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. AWS Config sets the state of a conformance pack to CREATE_IN_PROGRESS and
    UPDATE_IN_PROGRESS until the conformance pack is created or updated. You cannot update a conformance pack while
    it is in this state. You can create 50 conformance packs with 25 AWS Config rules in each pack and 3 delegated
    administrator per organization.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        organization_conformance_pack_name(Text): Name of the organization conformance pack you want to create.
        template_s3_uri(Text, optional): Location of file containing the template body. The uri must point to the conformance pack
            template (max size: 300 KB).  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. Defaults to None.
        delivery_s3_bucket(Text, optional): Amazon S3 bucket where AWS Config stores conformance pack templates.  This field is optional. If
            used, it must be prefixed with awsconfigconforms. 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.
        excluded_accounts(List, optional): A list of AWS accounts to be excluded from an organization conformance pack while deploying a
            conformance pack. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, organization_conformance_pack_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified organization conformance pack and all of the config rules and remediation actions from all
    member accounts in that organization.   Only a master account or a delegated administrator account can delete an
    organization conformance pack. When calling this API with a delegated administrator, you must ensure AWS
    Organizations ListDelegatedAdministrator permissions are added. AWS Config sets the state of a 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.
        organization_conformance_pack_name(Text): The name of organization conformance pack that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

