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

hub.exec.boto3.client.apprunner.create_service
hub.exec.boto3.client.apprunner.delete_service
hub.exec.boto3.client.apprunner.describe_service
hub.exec.boto3.client.apprunner.list_services
hub.exec.boto3.client.apprunner.pause_service
hub.exec.boto3.client.apprunner.resume_service
hub.exec.boto3.client.apprunner.update_service
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, service_name: Text, source_configuration: Dict, instance_configuration: Dict = None, tags: List = None, encryption_configuration: Dict = None, health_check_configuration: Dict = None, auto_scaling_configuration_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create an AWS App Runner service. After the service is created, the action also automatically starts a
    deployment. This is an asynchronous operation. On a successful call, you can use the returned OperationId and
    the ListOperations call to track the operation's progress.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        service_name(Text): A name for the new service. It must be unique across all the running App Runner services in your
            AWS account in the AWS Region.
        source_configuration(Dict): The source to deploy to the App Runner service. It can be a code or an image repository.
        instance_configuration(Dict, optional): The runtime configuration of instances (scaling units) of the App Runner service. Defaults to None.
        tags(List, optional): An optional list of metadata items that you can associate with your service resource. A tag is a
            key-value pair. Defaults to None.
        encryption_configuration(Dict, optional): An optional custom encryption key that App Runner uses to encrypt the copy of your source
            repository that it maintains and your service logs. By default, App Runner uses an AWS managed
            CMK. Defaults to None.
        health_check_configuration(Dict, optional): The settings for the health check that AWS App Runner performs to monitor the health of your
            service. Defaults to None.
        auto_scaling_configuration_arn(Text, optional): The Amazon Resource Name (ARN) of an App Runner automatic scaling configuration resource that
            you want to associate with your service. If not provided, App Runner associates the latest
            revision of a default auto scaling configuration. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apprunner.create_service(
                ctx,
                
                
                **{"ServiceName": service_name, "SourceConfiguration": source_configuration, "InstanceConfiguration": instance_configuration, "Tags": tags, "EncryptionConfiguration": encryption_configuration, "HealthCheckConfiguration": health_check_configuration, "AutoScalingConfigurationArn": auto_scaling_configuration_arn}
            )
            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.apprunner.describe_service(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, service_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete an AWS App Runner service. This is an asynchronous operation. On a successful call, you can use the
    returned OperationId and the ListOperations call to track the operation's progress.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        service_arn(Text): The Amazon Resource Name (ARN) of the App Runner service that you want to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

