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

hub.exec.boto3.client.lightsail.delete_container_image
hub.exec.boto3.client.lightsail.get_container_images
hub.exec.boto3.client.lightsail.register_container_image
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, service_name: Text, label: Text, digest: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Registers a container image to your Amazon Lightsail container service.  This action is not required if you
    install and use the Lightsail Control (lightsailctl) plugin to push container images to your Lightsail container
    service. For more information, see Pushing and managing container images on your Amazon Lightsail container
    services in the Amazon Lightsail Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        service_name(Text): The name of the container service for which to register a container image.
        label(Text): The label for the container image when it's registered to the container service. Use a
            descriptive label that you can use to track the different versions of your registered container
            images. Use the GetContainerImages action to return the container images registered to a
            Lightsail container service. The label is the <imagelabel> portion of the following image name
            example:    :container-service-1.<imagelabel>.1    If the name of your container service is
            mycontainerservice, and the label that you specify is mystaticwebsite, then the name of the
            registered container image will be :mycontainerservice.mystaticwebsite.1. The number at the end
            of these image name examples represents the version of the registered container image. If you
            push and register another container image to the same Lightsail container service, with the same
            label, then the version number for the new registered container image will be 2. If you push and
            register another container image, the version number will be 3, and so on.
        digest(Text): The digest of the container image to be registered.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.lightsail.container_image.present:
                - name: value
                - service_name: value
                - label: value
                - digest: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lightsail.container_image.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.lightsail.get_container_images(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lightsail.register_container_image(
                ctx,
                
                
                **{"serviceName": service_name, "label": label, "digest": digest}
            )
            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.lightsail.get_container_images(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, service_name: Text, image: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a container image that is registered to your Amazon Lightsail container service.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        service_name(Text): The name of the container service for which to delete a registered container image.
        image(Text): The name of the container image to delete from the container service. Use the GetContainerImages
            action to get the name of the container images that are registered to a container service.
            Container images sourced from your Lightsail container service, that are registered and stored
            on your service, start with a colon (:). For example, :container-service-1.mystaticwebsite.1.
            Container images sourced from a public registry like Docker Hub don't start with a colon. For
            example, nginx:latest or nginx.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

