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

hub.exec.boto3.client.gamelift.create_matchmaking_rule_set
hub.exec.boto3.client.gamelift.delete_matchmaking_rule_set
hub.exec.boto3.client.gamelift.describe_matchmaking_rule_sets
hub.exec.boto3.client.gamelift.validate_matchmaking_rule_set
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, rule_set_body: Text, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new rule set for FlexMatch matchmaking. A rule set describes the type of match to create, such as the
    number and size of teams. It also sets the parameters for acceptable player matches, such as minimum skill level
    or character type. A rule set is used by a MatchmakingConfiguration.  To create a matchmaking rule set, provide
    unique rule set name and the rule set body in JSON format. Rule sets must be defined in the same Region as the
    matchmaking configuration they are used with. Since matchmaking rule sets cannot be edited, it is a good idea to
    check the rule set syntax using ValidateMatchmakingRuleSet before creating a new rule set.  Learn more     Build
    a rule set     Design a matchmaker     Matchmaking with FlexMatch     Related actions
    CreateMatchmakingConfiguration | DescribeMatchmakingConfigurations | UpdateMatchmakingConfiguration |
    DeleteMatchmakingConfiguration | CreateMatchmakingRuleSet | DescribeMatchmakingRuleSets |
    ValidateMatchmakingRuleSet | DeleteMatchmakingRuleSet | All APIs by task

    Args:
        name(Text): A unique identifier for the matchmaking rule set. A matchmaking configuration identifies the
            rule set it uses by this name value. Note that the rule set name is different from the optional
            name field in the rule set body.
        rule_set_body(Text): A collection of matchmaking rules, formatted as a JSON string. Comments are not allowed in JSON,
            but most elements support a description field.
        tags(List, optional): A list of labels to assign to the new matchmaking rule set resource. Tags are developer-defined
            key-value pairs. Tagging AWS resources are useful for resource management, access management and
            cost allocation. For more information, see  Tagging AWS Resources in the AWS General Reference.
            Once the resource is created, you can use TagResource, UntagResource, and ListTagsForResource to
            add, remove, and view tags. The maximum tag limit may be lower than stated. See the AWS General
            Reference for actual tagging limits. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.gamelift.create_matchmaking_rule_set(
                ctx,
                
                
                **{"Name": name, "RuleSetBody": rule_set_body, "Tags": tags}
            )
            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.gamelift.describe_matchmaking_rule_sets(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an existing matchmaking rule set. To delete the rule set, provide the rule set name. Rule sets cannot be
    deleted if they are currently being used by a matchmaking configuration.   Learn more     Build a rule set
    Related actions   CreateMatchmakingConfiguration | DescribeMatchmakingConfigurations |
    UpdateMatchmakingConfiguration | DeleteMatchmakingConfiguration | CreateMatchmakingRuleSet |
    DescribeMatchmakingRuleSets | ValidateMatchmakingRuleSet | DeleteMatchmakingRuleSet | All APIs by task

    Args:
        name(Text): A unique identifier for the matchmaking rule set to be deleted. (Note: The rule set name is
            different from the optional "name" field in the rule set body.) You can use either the rule set
            name or ARN value.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

