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

hub.exec.boto3.client.imagebuilder.create_component
hub.exec.boto3.client.imagebuilder.delete_component
hub.exec.boto3.client.imagebuilder.get_component
hub.exec.boto3.client.imagebuilder.import_component
hub.exec.boto3.client.imagebuilder.list_components
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, semantic_version: Text, platform: Text, client_token: Text, description: Text = None, change_description: Text = None, supported_os_versions: List = None, data: Text = None, uri: Text = None, kms_key_id: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new component that can be used to build, validate, test, and assess your image.

    Args:
        name(Text): The name of the component.
        semantic_version(Text): The semantic version of the component. This version follows the semantic version syntax.  The
            semantic version has four nodes: <major>.<minor>.<patch>/<build>. You can assign values for the
            first three, and can filter on all of them.  Assignment: For the first three nodes you can
            assign any positive integer value, including zero, with an upper limit of 2^30-1, or 1073741823
            for each node. Image Builder automatically assigns the build number, and that is not open for
            updates.  Patterns: You can use any numeric pattern that adheres to the assignment requirements
            for the nodes that you can assign. For example, you might choose a software version pattern,
            such as 1.0.0, or a date, such as 2021.01.01.
        description(Text, optional): The description of the component. Describes the contents of the component. Defaults to None.
        change_description(Text, optional): The change description of the component. Describes what change has been made in this version, or
            what makes this version different from other versions of this component. Defaults to None.
        platform(Text): The platform of the component.
        supported_os_versions(List, optional):  The operating system (OS) version supported by the component. If the OS information is
            available, a prefix match is performed against the parent image OS version during image recipe
            creation. Defaults to None.
        data(Text, optional): The data of the component. Used to specify the data inline. Either data or uri can be used to
            specify the data within the component. Defaults to None.
        uri(Text, optional): The uri of the component. Must be an Amazon S3 URL and the requester must have permission to
            access the Amazon S3 bucket. If you use Amazon S3, you can specify component content up to your
            service quota. Either data or uri can be used to specify the data within the component. Defaults to None.
        kms_key_id(Text, optional): The ID of the KMS key that should be used to encrypt this component. Defaults to None.
        tags(Dict, optional): The tags of the component. Defaults to None.
        client_token(Text): The idempotency token of the component.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.imagebuilder.component.present:
                - name: value
                - semantic_version: value
                - platform: value
                - client_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.imagebuilder.component.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.imagebuilder.get_component(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.imagebuilder.create_component(
                ctx,
                
                
                **{"Name": name, "semanticVersion": semantic_version, "description": description, "changeDescription": change_description, "platform": platform, "supportedOsVersions": supported_os_versions, "data": data, "uri": uri, "kmsKeyId": kms_key_id, "tags": tags, "clientToken": client_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.imagebuilder.get_component(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, component_build_version_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes a component build version.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

