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

hub.exec.boto3.client.application_insights.create_log_pattern
hub.exec.boto3.client.application_insights.delete_log_pattern
hub.exec.boto3.client.application_insights.describe_log_pattern
hub.exec.boto3.client.application_insights.list_log_patterns
hub.exec.boto3.client.application_insights.update_log_pattern
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, resource_group_name: Text, pattern_set_name: Text, pattern_name: Text, pattern: Text, rank: int)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds an log pattern to a LogPatternSet.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_group_name(Text): The name of the resource group.
        pattern_set_name(Text): The name of the log pattern set.
        pattern_name(Text): The name of the log pattern.
        pattern(Text): The log pattern. The pattern must be DFA compatible. Patterns that utilize forward lookahead or
            backreference constructions are not supported.
        rank(int): Rank of the log pattern. Must be a value between 1 and 1,000,000. The patterns are sorted by
            rank, so we recommend that you set your highest priority patterns with the lowest rank. A
            pattern of rank 1 will be the first to get matched to a log line. A pattern of rank 1,000,000
            will be last to get matched. When you configure custom log patterns from the console, a Low
            severity pattern translates to a 750,000 rank. A Medium severity pattern translates to a 500,000
            rank. And a High severity pattern translates to a 250,000 rank. Rank values less than 1 or
            greater than 1,000,000 are reserved for AWS-provided patterns.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.application_insights.log_pattern.present:
                - name: value
                - resource_group_name: value
                - pattern_set_name: value
                - pattern_name: value
                - pattern: value
                - rank: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.application_insights.log_pattern.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.application_insights.describe_log_pattern(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.application_insights.create_log_pattern(
                ctx,
                
                
                **{"ResourceGroupName": resource_group_name, "PatternSetName": pattern_set_name, "PatternName": pattern_name, "Pattern": pattern, "Rank": rank}
            )
            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.application_insights.describe_log_pattern(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, resource_group_name: Text, pattern_set_name: Text, pattern_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes the specified log pattern from a LogPatternSet.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_group_name(Text): The name of the resource group.
        pattern_set_name(Text): The name of the log pattern set.
        pattern_name(Text): The name of the log pattern.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.application_insights.log_pattern.absent:
                - name: value
                - resource_group_name: value
                - pattern_set_name: value
                - pattern_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.application_insights.log_pattern.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.application_insights.describe_log_pattern(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.application_insights.delete_log_pattern(
                ctx,
                
                
                **{"ResourceGroupName": resource_group_name, "PatternSetName": pattern_set_name, "PatternName": pattern_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.application_insights.describe_log_pattern(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

