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

hub.exec.boto3.client.personalize.create_schema
hub.exec.boto3.client.personalize.delete_schema
hub.exec.boto3.client.personalize.describe_schema
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, schema: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon Personalize schema from the specified schema string. The schema you create must be in Avro
    JSON format. Amazon Personalize recognizes three schema variants. Each schema is associated with a dataset type
    and has a set of required field and keywords. You specify a schema when you call CreateDataset.  Related APIs
    ListSchemas     DescribeSchema     DeleteSchema

    Args:
        name(Text): The name for the schema.
        schema(Text): A schema in Avro JSON format.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.personalize.create_schema(
                ctx,
                
                
                **{"Name": name, "schema": schema}
            )
            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.personalize.describe_schema(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, schema_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a schema. Before deleting a schema, you must delete all datasets referencing the schema. For more
    information on schemas, see CreateSchema.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        schema_arn(Text): The Amazon Resource Name (ARN) of the schema to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

