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

hub.exec.boto3.client.transcribe.create_call_analytics_category
hub.exec.boto3.client.transcribe.delete_call_analytics_category
hub.exec.boto3.client.transcribe.get_call_analytics_category
hub.exec.boto3.client.transcribe.list_call_analytics_categories
hub.exec.boto3.client.transcribe.update_call_analytics_category
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, category_name: Text, rules: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an analytics category. Amazon Transcribe applies the conditions specified by your analytics categories
    to your call analytics jobs. For each analytics category, you specify one or more rules. For example, you can
    specify a rule that the customer sentiment was neutral or negative within that category. If you start a call
    analytics job, Amazon Transcribe applies the category to the analytics job that you've specified.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        category_name(Text): The name that you choose for your category when you create it.
        rules(List): To create a category, you must specify between 1 and 20 rules. For each rule, you specify a
            filter to be applied to the attributes of the call. For example, you can specify a sentiment
            filter to detect if the customer's sentiment was negative or neutral.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.transcribe.call_analytics_category.present:
                - name: value
                - category_name: value
                - rules: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.transcribe.call_analytics_category.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.transcribe.get_call_analytics_category(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.transcribe.create_call_analytics_category(
                ctx,
                
                
                **{"CategoryName": category_name, "Rules": rules}
            )
            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.transcribe.get_call_analytics_category(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, category_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a call analytics category using its name.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        category_name(Text): The name of the call analytics category that you're choosing to delete. The value is case
            sensitive.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

