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

hub.exec.boto3.client.healthlake.create_fhir_datastore
hub.exec.boto3.client.healthlake.delete_fhir_datastore
hub.exec.boto3.client.healthlake.describe_fhir_datastore
hub.exec.boto3.client.healthlake.list_fhir_datastores
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, datastore_type_version: Text, datastore_name: Text = None, sse_configuration: Dict = None, preload_data_config: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Data Store that can ingest and export FHIR formatted data.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        datastore_name(Text, optional): The user generated name for the Data Store. Defaults to None.
        datastore_type_version(Text): The FHIR version of the Data Store. The only supported version is R4.
        sse_configuration(Dict, optional):  The server-side encryption key configuration for a customer provided encryption key specified
            for creating a Data Store. Defaults to None.
        preload_data_config(Dict, optional): Optional parameter to preload data upon creation of the Data Store. Currently, the only
            supported preloaded data is synthetic data generated from Synthea. Defaults to None.
        tags(List, optional):  Resource tags that are applied to a Data Store when it is created. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.healthlake.fhir_datastore.present:
                - name: value
                - datastore_type_version: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.healthlake.fhir_datastore.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.healthlake.describe_fhir_datastore(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.healthlake.create_fhir_datastore(
                ctx,
                
                ClientToken=name,
                **{"DatastoreName": datastore_name, "DatastoreTypeVersion": datastore_type_version, "SseConfiguration": sse_configuration, "PreloadDataConfig": preload_data_config, "Tags": tags}
            )
            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.healthlake.describe_fhir_datastore(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, datastore_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a Data Store.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        datastore_id(Text, optional):  The AWS-generated ID for the Data Store to be deleted. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

