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

hub.exec.boto3.client.cloudformation.activate_type
hub.exec.boto3.client.cloudformation.deactivate_type
hub.exec.boto3.client.cloudformation.deregister_type
hub.exec.boto3.client.cloudformation.describe_type
hub.exec.boto3.client.cloudformation.list_types
hub.exec.boto3.client.cloudformation.publish_type
hub.exec.boto3.client.cloudformation.register_type
hub.exec.boto3.client.cloudformation.test_type
"""



from typing import *
import dict_tools.differ as differ


__virtualname__ = "type"
async def present(hub, ctx, name: Text, type_name: Text, schema_handler_package: Text, type_: Text = None, logging_config: Dict = None, execution_role_arn: Text = None, client_request_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Registers an extension with the CloudFormation service. Registering an extension makes it available for use in
    CloudFormation templates in your account, and includes:   Validating the extension schema   Determining which
    handlers, if any, have been specified for the extension   Making the extension available for use in your account
    For more information on how to develop extensions and ready them for registeration, see Creating Resource
    Providers in the CloudFormation CLI User Guide. You can have a maximum of 50 resource extension versions
    registered at a time. This maximum is per account and per region. Use DeregisterType to deregister specific
    extension versions if necessary. Once you have initiated a registration request using  RegisterType , you can
    use  DescribeTypeRegistration  to monitor the progress of the registration request. Once you have registered a
    private extension in your account and region, use SetTypeConfiguration to specify configuration properties for
    the extension. For more information, see Configuring extensions at the account level in the CloudFormation User
    Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        type_(Text, optional): The kind of extension. Defaults to None.
        type_name(Text): The name of the extension being registered. We recommend that extension names adhere to the
            following patterns:    For resource types, company_or_organization::service::type.   For
            modules, company_or_organization::service::type::MODULE.    The following organization
            namespaces are reserved and cannot be used in your extension names:    Alexa     AMZN     Amazon
            AWS     Custom     Dev.
        schema_handler_package(Text): A url to the S3 bucket containing the extension project package that contains the neccessary
            files for the extension you want to register. For information on generating a schema handler
            package for the extension you want to register, see submit in the CloudFormation CLI User Guide.
            The user registering the extension must be able to access the package in the S3 bucket. That is,
            the user needs to have GetObject permissions for the schema handler package. For more
            information, see Actions, Resources, and Condition Keys for Amazon S3 in the Identity and Access
            Management User Guide.
        logging_config(Dict, optional): Specifies logging configuration information for an extension. Defaults to None.
        execution_role_arn(Text, optional): The Amazon Resource Name (ARN) of the IAM role for CloudFormation to assume when invoking the
            extension. For CloudFormation to assume the specified execution role, the role must contain a
            trust relationship with the CloudFormation service principle
            (resources.cloudformation.amazonaws.com). For more information on adding trust relationships,
            see Modifying a role trust policy in the Identity and Access Management User Guide. If your
            extension calls Amazon Web Services APIs in any of its handlers, you must create an  IAM
            execution role  that includes the necessary permissions to call those Amazon Web Services APIs,
            and provision that execution role in your account. When CloudFormation needs to invoke the
            resource type handler, CloudFormation assumes this execution role to create a temporary session
            token, which it then passes to the resource type handler, thereby supplying your resource type
            with the appropriate credentials. Defaults to None.
        client_request_token(Text, optional): A unique identifier that acts as an idempotency key for this registration request. Specifying a
            client request token prevents CloudFormation from generating more than one version of an
            extension from the same registeration request, even if the request is submitted multiple times. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cloudformation.type_.present:
                - name: value
                - type_name: value
                - schema_handler_package: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudformation.type.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.cloudformation.describe_type(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudformation.register_type(
                ctx,
                
                
                **{"Type": type_, "TypeName": type_name, "SchemaHandlerPackage": schema_handler_package, "LoggingConfig": logging_config, "ExecutionRoleArn": execution_role_arn, "ClientRequestToken": client_request_token}
            )
            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.cloudformation.describe_type(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, arn: Text = None, type_: Text = None, type_name: Text = None, version_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Marks an extension or extension version as DEPRECATED in the CloudFormation registry, removing it from active
    use. Deprecated extensions or extension versions cannot be used in CloudFormation operations. To deregister an
    entire extension, you must individually deregister all active versions of that extension. If an extension has
    only a single active version, deregistering that version results in the extension itself being deregistered and
    marked as deprecated in the registry.  You cannot deregister the default version of an extension if there are
    other active version of that extension. If you do deregister the default version of an extension, the
    textensionype itself is deregistered as well and marked as deprecated.  To view the deprecation status of an
    extension or extension version, use DescribeType.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        arn(Text, optional): The Amazon Resource Name (ARN) of the extension. Conditional: You must specify either TypeName
            and Type, or Arn. Defaults to None.
        type_(Text, optional): The kind of extension. Conditional: You must specify either TypeName and Type, or Arn. Defaults to None.
        type_name(Text, optional): The name of the extension. Conditional: You must specify either TypeName and Type, or Arn. Defaults to None.
        version_id(Text, optional): The ID of a specific version of the extension. The version ID is the value at the end of the
            Amazon Resource Name (ARN) assigned to the extension version when it is registered. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudformation.deregister_type(
                ctx,
                
                
                **{"Arn": arn, "Type": type_, "TypeName": type_name, "VersionId": version_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.cloudformation.describe_type(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

