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

hub.exec.boto3.client.codestar_notifications.create_notification_rule
hub.exec.boto3.client.codestar_notifications.delete_notification_rule
hub.exec.boto3.client.codestar_notifications.describe_notification_rule
hub.exec.boto3.client.codestar_notifications.list_notification_rules
hub.exec.boto3.client.codestar_notifications.update_notification_rule
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, event_type_ids: List, resource: Text, targets: List, detail_type: Text, client_request_token: Text = None, tags: Dict = None, status: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a notification rule for a resource. The rule specifies the events you want notifications about and the
    targets (such as SNS topics) where you want to receive them.

    Args:
        name(Text): The name for the notification rule. Notifictaion rule names must be unique in your AWS account.
        event_type_ids(List): A list of event types associated with this notification rule. For a list of allowed events, see
            EventTypeSummary.
        resource(Text): The Amazon Resource Name (ARN) of the resource to associate with the notification rule.
            Supported resources include pipelines in AWS CodePipeline, repositories in AWS CodeCommit, and
            build projects in AWS CodeBuild.
        targets(List): A list of Amazon Resource Names (ARNs) of SNS topics to associate with the notification rule.
        detail_type(Text): The level of detail to include in the notifications for this resource. BASIC will include only
            the contents of the event as it would appear in AWS CloudWatch. FULL will include any
            supplemental information provided by AWS CodeStar Notifications and/or the service for the
            resource for which the notification is created.
        client_request_token(Text, optional): A unique, client-generated idempotency token that, when provided in a request, ensures the
            request cannot be repeated with a changed parameter. If a request with the same parameters is
            received and a token is included, the request returns information about the initial request that
            used that token.  The AWS SDKs prepopulate client request tokens. If you are using an AWS SDK,
            an idempotency token is created for you. Defaults to None.
        tags(Dict, optional): A list of tags to apply to this notification rule. Key names cannot start with "aws". Defaults to None.
        status(Text, optional): The status of the notification rule. The default value is ENABLED. If the status is set to
            DISABLED, notifications aren't sent for the notification rule. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.codestar_notifications.notification_rule.present:
                - name: value
                - event_type_ids: value
                - resource: value
                - targets: value
                - detail_type: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.codestar_notifications.notification_rule.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.codestar_notifications.describe_notification_rule(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.codestar_notifications.create_notification_rule(
                ctx,
                
                
                **{"Name": name, "EventTypeIds": event_type_ids, "Resource": resource, "Targets": targets, "DetailType": detail_type, "ClientRequestToken": client_request_token, "Tags": tags, "Status": status}
            )
            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.codestar_notifications.describe_notification_rule(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a notification rule for a resource.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        arn(Text): The Amazon Resource Name (ARN) of the notification rule you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

