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

hub.exec.boto3.client.codecommit.create_approval_rule_template
hub.exec.boto3.client.codecommit.delete_approval_rule_template
hub.exec.boto3.client.codecommit.get_approval_rule_template
hub.exec.boto3.client.codecommit.list_approval_rule_templates
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, approval_rule_template_name: Text, approval_rule_template_content: Text, approval_rule_template_description: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a template for approval rules that can then be associated with one or more repositories in your AWS
    account. When you associate a template with a repository, AWS CodeCommit creates an approval rule that matches
    the conditions of the template for all pull requests that meet the conditions of the template. For more
    information, see AssociateApprovalRuleTemplateWithRepository.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        approval_rule_template_name(Text): The name of the approval rule template. Provide descriptive names, because this name is applied
            to the approval rules created automatically in associated repositories.
        approval_rule_template_content(Text): The content of the approval rule that is created on pull requests in associated repositories. If
            you specify one or more destination references (branches), approval rules are created in an
            associated repository only if their destination references (branches) match those specified in
            the template.  When you create the content of the approval rule template, you can specify
            approvers in an approval pool in one of two ways:    CodeCommitApprovers: This option only
            requires an AWS account and a resource. It can be used for both IAM users and federated access
            users whose name matches the provided resource name. This is a very powerful option that offers
            a great deal of flexibility. For example, if you specify the AWS account 123456789012 and
            Mary_Major, all of the following are counted as approvals coming from that user:   An IAM user
            in the account (arn:aws:iam::123456789012:user/Mary_Major)   A federated user identified in IAM
            as Mary_Major (arn:aws:sts::123456789012:federated-user/Mary_Major)   This option does not
            recognize an active session of someone assuming the role of CodeCommitReview with a role session
            name of Mary_Major (arn:aws:sts::123456789012:assumed-role/CodeCommitReview/Mary_Major) unless
            you include a wildcard (*Mary_Major).    Fully qualified ARN: This option allows you to specify
            the fully qualified Amazon Resource Name (ARN) of the IAM user or role.    For more information
            about IAM ARNs, wildcards, and formats, see IAM Identifiers in the IAM User Guide.
        approval_rule_template_description(Text, optional): The description of the approval rule template. Consider providing a description that explains
            what this template does and when it might be appropriate to associate it with repositories. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.codecommit.approval_rule_template.present:
                - name: value
                - approval_rule_template_name: value
                - approval_rule_template_content: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.codecommit.approval_rule_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.codecommit.get_approval_rule_template(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.codecommit.create_approval_rule_template(
                ctx,
                
                
                **{"approvalRuleTemplateName": approval_rule_template_name, "approvalRuleTemplateContent": approval_rule_template_content, "approvalRuleTemplateDescription": approval_rule_template_description}
            )
            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.codecommit.get_approval_rule_template(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, approval_rule_template_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a specified approval rule template. Deleting a template does not remove approval rules on pull requests
    already created with the template.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        approval_rule_template_name(Text): The name of the approval rule template to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.codecommit.approval_rule_template.absent:
                - name: value
                - approval_rule_template_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.codecommit.approval_rule_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.codecommit.get_approval_rule_template(name)

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

