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

hub.exec.boto3.client.elasticbeanstalk.create_platform_version
hub.exec.boto3.client.elasticbeanstalk.delete_platform_version
hub.exec.boto3.client.elasticbeanstalk.describe_platform_version
hub.exec.boto3.client.elasticbeanstalk.list_platform_versions
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, platform_name: Text, platform_version: Text, platform_definition_bundle: Dict, environment_name: Text = None, option_settings: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create a new version of your custom platform.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        platform_name(Text): The name of your custom platform.
        platform_version(Text): The number, such as 1.0.2, for the new platform version.
        platform_definition_bundle(Dict): The location of the platform definition archive in Amazon S3.
        environment_name(Text, optional): The name of the builder environment. Defaults to None.
        option_settings(List, optional): The configuration option settings to apply to the builder environment. Defaults to None.
        tags(List, optional): Specifies the tags applied to the new platform version. Elastic Beanstalk applies these tags
            only to the platform version. Environments that you create using the platform version don't
            inherit the tags. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.elasticbeanstalk.platform_version.present:
                - name: value
                - platform_name: value
                - platform_version: value
                - platform_definition_bundle: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.elasticbeanstalk.platform_version.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.elasticbeanstalk.describe_platform_version(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.elasticbeanstalk.create_platform_version(
                ctx,
                
                
                **{"PlatformName": platform_name, "PlatformVersion": platform_version, "PlatformDefinitionBundle": platform_definition_bundle, "EnvironmentName": environment_name, "OptionSettings": option_settings, "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.elasticbeanstalk.describe_platform_version(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, platform_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified version of a custom platform.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        platform_arn(Text, optional): The ARN of the version of the custom platform. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

