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

hub.exec.boto3.client.personalize.create_filter
hub.exec.boto3.client.personalize.delete_filter
hub.exec.boto3.client.personalize.describe_filter
hub.exec.boto3.client.personalize.list_filters
"""



from typing import *
import dict_tools.differ as differ


__virtualname__ = "filter"
async def present(hub, ctx, name: Text, dataset_group_arn: Text, filter_expression: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a recommendation filter. For more information, see filter.

    Args:
        name(Text): The name of the filter to create.
        dataset_group_arn(Text): The ARN of the dataset group that the filter will belong to.
        filter_expression(Text): The filter expression defines which items are included or excluded from recommendations. Filter
            expression must follow specific format rules. For information about filter expression structure
            and syntax, see filter-expressions.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.personalize.filter_.present:
                - name: value
                - dataset_group_arn: value
                - filter_expression: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.personalize.filter.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.personalize.describe_filter(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.personalize.create_filter(
                ctx,
                
                
                **{"Name": name, "datasetGroupArn": dataset_group_arn, "filterExpression": filter_expression}
            )
            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.personalize.describe_filter(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, filter_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a filter.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        filter_arn(Text): The ARN of the filter to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

