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

hub.exec.boto3.client.appsync.create_data_source
hub.exec.boto3.client.appsync.delete_data_source
hub.exec.boto3.client.appsync.get_data_source
hub.exec.boto3.client.appsync.list_data_sources
hub.exec.boto3.client.appsync.update_data_source
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, api_id: Text, type_: Text, description: Text = None, service_role_arn: Text = None, dynamodb_config: Dict = None, lambda_config: Dict = None, elasticsearch_config: Dict = None, http_config: Dict = None, relational_database_config: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a DataSource object.

    Args:
        name(Text): A user-supplied name for the DataSource.
        api_id(Text): The API ID for the GraphQL API for the DataSource.
        description(Text, optional): A description of the DataSource. Defaults to None.
        type_(Text): The type of the DataSource.
        service_role_arn(Text, optional): The Identity and Access Management service role ARN for the data source. The system assumes this
            role when accessing the data source. Defaults to None.
        dynamodb_config(Dict, optional): Amazon DynamoDB settings. Defaults to None.
        lambda_config(Dict, optional): Amazon Web Services Lambda settings. Defaults to None.
        elasticsearch_config(Dict, optional): Amazon Elasticsearch Service settings. Defaults to None.
        http_config(Dict, optional): HTTP endpoint settings. Defaults to None.
        relational_database_config(Dict, optional): Relational database settings. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.appsync.create_data_source(
                ctx,
                
                
                **{"Name": name, "apiId": api_id, "description": description, "type": type_, "serviceRoleArn": service_role_arn, "dynamodbConfig": dynamodb_config, "lambdaConfig": lambda_config, "elasticsearchConfig": elasticsearch_config, "httpConfig": http_config, "relationalDatabaseConfig": relational_database_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_data_source(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): The name of the data source.
        api_id(Text): The API ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

