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

hub.exec.boto3.client.glue.delete_schema_versions
hub.exec.boto3.client.glue.get_schema_version
hub.exec.boto3.client.glue.list_schema_versions
hub.exec.boto3.client.glue.register_schema_version
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, schema_id: Dict, schema_definition: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds a new version to the existing schema. Returns an error if new version of schema does not meet the
    compatibility requirements of the schema set. This API will not create a new schema set and will return a 404
    error if the schema set is not already present in the Schema Registry. If this is the first schema definition to
    be registered in the Schema Registry, this API will store the schema version and return immediately. Otherwise,
    this call has the potential to run longer than other operations due to compatibility modes. You can call the
    GetSchemaVersion API with the SchemaVersionId to check compatibility modes. If the same schema definition is
    already stored in Schema Registry as a version, the schema ID of the existing schema is returned to the caller.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        schema_id(Dict): This is a wrapper structure to contain schema identity fields. The structure contains:
            SchemaId$SchemaArn: The Amazon Resource Name (ARN) of the schema. Either SchemaArn or SchemaName
            and RegistryName has to be provided.   SchemaId$SchemaName: The name of the schema. Either
            SchemaArn or SchemaName and RegistryName has to be provided.
        schema_definition(Text): The schema definition using the DataFormat setting for the SchemaName.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.glue.schema_version.present:
                - name: value
                - schema_id: value
                - schema_definition: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.glue.schema_version.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.glue.get_schema_version(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.glue.register_schema_version(
                ctx,
                
                
                **{"SchemaId": schema_id, "SchemaDefinition": schema_definition}
            )
            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.glue.get_schema_version(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, schema_id: Dict, versions: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Remove versions from the specified schema. A version number or range may be supplied. If the compatibility mode
    forbids deleting of a version that is necessary, such as BACKWARDS_FULL, an error is returned. Calling the
    GetSchemaVersions API after this call will list the status of the deleted versions. When the range of version
    numbers contain check pointed version, the API will return a 409 conflict and will not proceed with the
    deletion. You have to remove the checkpoint first using the DeleteSchemaCheckpoint API before using this API.
    You cannot use the DeleteSchemaVersions API to delete the first schema version in the schema set. The first
    schema version can only be deleted by the DeleteSchema API. This operation will also delete the attached
    SchemaVersionMetadata under the schema versions. Hard deletes will be enforced on the database. If the
    compatibility mode forbids deleting of a version that is necessary, such as BACKWARDS_FULL, an error is
    returned.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        schema_id(Dict): This is a wrapper structure that may contain the schema name and Amazon Resource Name (ARN).
        versions(Text): A version range may be supplied which may be of the format:   a single version number, 5   a
            range, 5-8 : deletes versions 5, 6, 7, 8.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.glue.delete_schema_versions(
                ctx,
                
                
                **{"SchemaId": schema_id, "Versions": versions}
            )
            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.glue.get_schema_version(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

