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

hub.exec.boto3.client.appsync.create_function
hub.exec.boto3.client.appsync.delete_function
hub.exec.boto3.client.appsync.get_function
hub.exec.boto3.client.appsync.list_functions
hub.exec.boto3.client.appsync.update_function
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, api_id: Text, data_source_name: Text, function_version: Text, description: Text = None, request_mapping_template: Text = None, response_mapping_template: Text = None, sync_config: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Function object. A function is a reusable entity. Multiple functions can be used to compose the
    resolver logic.

    Args:
        name(Text): The Function name. The function name does not have to be unique.
        api_id(Text): The GraphQL API ID.
        description(Text, optional): The Function description. Defaults to None.
        data_source_name(Text): The Function DataSource name.
        request_mapping_template(Text, optional): The Function request mapping template. Functions support only the 2018-05-29 version of the
            request mapping template. Defaults to None.
        response_mapping_template(Text, optional): The Function response mapping template. Defaults to None.
        function_version(Text): The version of the request mapping template. Currently the supported value is 2018-05-29.
        sync_config(Dict, optional): Describes a Sync configuration for a resolver. Contains information on which Conflict Detection
            as well as Resolution strategy should be performed when the resolver is invoked. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.appsync.function.present:
                - name: value
                - api_id: value
                - data_source_name: value
                - function_version: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.appsync.function.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.appsync.get_function(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appsync.create_function(
                ctx,
                
                
                **{"Name": name, "apiId": api_id, "description": description, "dataSourceName": data_source_name, "requestMappingTemplate": request_mapping_template, "responseMappingTemplate": response_mapping_template, "functionVersion": function_version, "syncConfig": sync_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.appsync.get_function(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The GraphQL API ID.
        function_id(Text): The Function ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

