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

hub.exec.boto3.client.ssm.create_document
hub.exec.boto3.client.ssm.delete_document
hub.exec.boto3.client.ssm.describe_document
hub.exec.boto3.client.ssm.get_document
hub.exec.boto3.client.ssm.list_documents
hub.exec.boto3.client.ssm.update_document
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, content: Text, requires: List = None, attachments: List = None, display_name: Text = None, version_name: Text = None, document_type: Text = None, document_format: Text = None, target_type: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Amazon Web Services Systems Manager (SSM document). An SSM document defines the actions that Systems
    Manager performs on your managed instances. For more information about SSM documents, including information
    about supported schemas, features, and syntax, see Amazon Web Services Systems Manager Documents in the Amazon
    Web Services Systems Manager User Guide.

    Args:
        name(Text): A name for the SSM document.  You can't use the following strings as document name prefixes.
            These are reserved by Amazon Web Services for use as document name prefixes:    aws-     amazon
            amzn.
        content(Text): The content for the new SSM document in JSON or YAML format. We recommend storing the contents
            for your new document in an external JSON or YAML file and referencing the file in a command.
            For examples, see the following topics in the Amazon Web Services Systems Manager User Guide.
            Create an SSM document (Amazon Web Services API)     Create an SSM document (Amazon Web Services
            CLI)     Create an SSM document (API).
        requires(List, optional): A list of SSM documents required by a document. This parameter is used exclusively by AppConfig.
            When a user creates an AppConfig configuration in an SSM document, the user must also specify a
            required document for validation purposes. In this case, an ApplicationConfiguration document
            requires an ApplicationConfigurationSchema document for validation purposes. For more
            information, see What is AppConfig? in the AppConfig User Guide. Defaults to None.
        attachments(List, optional): A list of key-value pairs that describe attachments to a version of a document. Defaults to None.
        display_name(Text, optional): An optional field where you can specify a friendly name for the SSM document. This value can
            differ for each version of the document. You can update this value at a later time using the
            UpdateDocument operation. Defaults to None.
        version_name(Text, optional): An optional field specifying the version of the artifact you are creating with the document. For
            example, "Release 12, Update 6". This value is unique across all versions of a document, and
            can't be changed. Defaults to None.
        document_type(Text, optional): The type of document to create. Defaults to None.
        document_format(Text, optional): Specify the document format for the request. The document format can be JSON, YAML, or TEXT.
            JSON is the default format. Defaults to None.
        target_type(Text, optional): Specify a target type to define the kinds of resources the document can run on. For example, to
            run a document on EC2 instances, specify the following value: /AWS::EC2::Instance. If you
            specify a value of '/' the document can run on all types of resources. If you don't specify a
            value, the document can't run on any resources. For a list of valid resource types, see Amazon
            Web Services resource and property types reference in the CloudFormation User Guide. Defaults to None.
        tags(List, optional): Optional metadata that you assign to a resource. Tags enable you to categorize a resource in
            different ways, such as by purpose, owner, or environment. For example, you might want to tag an
            SSM document to identify the types of targets or the environment where it will run. In this
            case, you could specify the following key-value pairs:    Key=OS,Value=Windows
            Key=Environment,Value=Production     To add tags to an existing SSM document, use the
            AddTagsToResource operation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm.create_document(
                ctx,
                
                
                **{"Name": name, "Content": content, "Requires": requires, "Attachments": attachments, "DisplayName": display_name, "VersionName": version_name, "DocumentType": document_type, "DocumentFormat": document_format, "TargetType": target_type, "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.ssm.describe_document(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, document_version: Text = None, version_name: Text = None, force: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the Amazon Web Services Systems Manager document (SSM document) and all instance associations to the
    document. Before you delete the document, we recommend that you use DeleteAssociation to disassociate all
    instances that are associated with the document.

    Args:
        name(Text): The name of the document.
        document_version(Text, optional): The version of the document that you want to delete. If not provided, all versions of the
            document are deleted. Defaults to None.
        version_name(Text, optional): The version name of the document that you want to delete. If not provided, all versions of the
            document are deleted. Defaults to None.
        force(bool, optional): Some SSM document types require that you specify a Force flag before you can delete the
            document. For example, you must specify a Force flag to delete a document of type
            ApplicationConfigurationSchema. You can restrict access to the Force flag in an Identity and
            Access Management (IAM) policy. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm.delete_document(
                ctx,
                
                
                **{"Name": name, "DocumentVersion": document_version, "VersionName": version_name, "Force": force}
            )
            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.ssm.describe_document(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

