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

hub.exec.boto3.client.appsync.create_resolver
hub.exec.boto3.client.appsync.delete_resolver
hub.exec.boto3.client.appsync.get_resolver
hub.exec.boto3.client.appsync.list_resolvers
hub.exec.boto3.client.appsync.update_resolver
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, api_id: Text, type_name: Text, field_name: Text, data_source_name: Text = None, request_mapping_template: Text = None, response_mapping_template: Text = None, kind: Text = None, pipeline_config: Dict = None, sync_config: Dict = None, caching_config: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Resolver object. A resolver converts incoming requests into a format that a data source can understand
    and converts the data source's responses into GraphQL.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The ID for the GraphQL API for which the resolver is being created.
        type_name(Text): The name of the Type.
        field_name(Text): The name of the field to attach the resolver to.
        data_source_name(Text, optional): The name of the data source for which the resolver is being created. Defaults to None.
        request_mapping_template(Text, optional): The mapping template to be used for requests. A resolver uses a request mapping template to
            convert a GraphQL expression into a format that a data source can understand. Mapping templates
            are written in Apache Velocity Template Language (VTL). VTL request mapping templates are
            optional when using a Lambda data source. For all other data sources, VTL request and response
            mapping templates are required. Defaults to None.
        response_mapping_template(Text, optional): The mapping template to be used for responses from the data source. Defaults to None.
        kind(Text, optional): The resolver type.    UNIT: A UNIT resolver type. A UNIT resolver is the default resolver type.
            A UNIT resolver enables you to execute a GraphQL query against a single data source.
            PIPELINE: A PIPELINE resolver type. A PIPELINE resolver enables you to execute a series of
            Function in a serial manner. You can use a pipeline resolver to execute a GraphQL query against
            multiple data sources. Defaults to None.
        pipeline_config(Dict, optional): The PipelineConfig. Defaults to None.
        sync_config(Dict, optional): The SyncConfig for a resolver attached to a versioned datasource. Defaults to None.
        caching_config(Dict, optional): The caching configuration for the resolver. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appsync.create_resolver(
                ctx,
                
                
                **{"apiId": api_id, "typeName": type_name, "fieldName": field_name, "dataSourceName": data_source_name, "requestMappingTemplate": request_mapping_template, "responseMappingTemplate": response_mapping_template, "kind": kind, "pipelineConfig": pipeline_config, "syncConfig": sync_config, "cachingConfig": caching_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_resolver(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The API ID.
        type_name(Text): The name of the resolver type.
        field_name(Text): The resolver field name.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

