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

hub.exec.boto3.client.lambda_.create_alias
hub.exec.boto3.client.lambda_.delete_alias
hub.exec.boto3.client.lambda_.get_alias
hub.exec.boto3.client.lambda_.list_aliases
hub.exec.boto3.client.lambda_.update_alias
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, function_name: Text, function_version: Text, description: Text = None, routing_config: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an alias for a Lambda function version. Use aliases to provide clients with a function identifier that
    you can update to invoke a different version. You can also map an alias to split invocation requests between two
    versions. Use the RoutingConfig parameter to specify a second version and the percentage of invocation requests
    that it receives.

    Args:
        name(Text): The name of the alias.
        function_name(Text): The name of the Lambda function.  Name formats     Function name - MyFunction.    Function ARN -
            arn:aws:lambda:us-west-2:123456789012:function:MyFunction.    Partial ARN -
            123456789012:function:MyFunction.   The length constraint applies only to the full ARN. If you
            specify only the function name, it is limited to 64 characters in length.
        function_version(Text): The function version that the alias invokes.
        description(Text, optional): A description of the alias. Defaults to None.
        routing_config(Dict, optional): The routing configuration of the alias. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.lambda_.alias.present:
                - name: value
                - function_name: value
                - function_version: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lambda_.alias.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.lambda_.get_alias(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lambda_.create_alias(
                ctx,
                
                
                **{"Name": name, "FunctionName": function_name, "FunctionVersion": function_version, "Description": description, "RoutingConfig": routing_config}
            )
            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.lambda_.get_alias(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): The name of the alias.
        function_name(Text): The name of the Lambda function.  Name formats     Function name - MyFunction.    Function ARN -
            arn:aws:lambda:us-west-2:123456789012:function:MyFunction.    Partial ARN -
            123456789012:function:MyFunction.   The length constraint applies only to the full ARN. If you
            specify only the function name, it is limited to 64 characters in length.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

