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

hub.exec.boto3.client.devicefarm.create_upload
hub.exec.boto3.client.devicefarm.delete_upload
hub.exec.boto3.client.devicefarm.get_upload
hub.exec.boto3.client.devicefarm.list_uploads
hub.exec.boto3.client.devicefarm.update_upload
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, project_arn: Text, type_: Text, content_type: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Uploads an app or test scripts.

    Args:
        name(Text): The upload's file name. The name should not contain any forward slashes (/). If you are
            uploading an iOS app, the file name must end with the .ipa extension. If you are uploading an
            Android app, the file name must end with the .apk extension. For all others, the file name must
            end with the .zip file extension.
        project_arn(Text): The ARN of the project for the upload.
        type_(Text): The upload's upload type. Must be one of the following values:   ANDROID_APP   IOS_APP   WEB_APP
            EXTERNAL_DATA   APPIUM_JAVA_JUNIT_TEST_PACKAGE   APPIUM_JAVA_TESTNG_TEST_PACKAGE
            APPIUM_PYTHON_TEST_PACKAGE   APPIUM_NODE_TEST_PACKAGE   APPIUM_RUBY_TEST_PACKAGE
            APPIUM_WEB_JAVA_JUNIT_TEST_PACKAGE   APPIUM_WEB_JAVA_TESTNG_TEST_PACKAGE
            APPIUM_WEB_PYTHON_TEST_PACKAGE   APPIUM_WEB_NODE_TEST_PACKAGE   APPIUM_WEB_RUBY_TEST_PACKAGE
            CALABASH_TEST_PACKAGE   INSTRUMENTATION_TEST_PACKAGE   UIAUTOMATION_TEST_PACKAGE
            UIAUTOMATOR_TEST_PACKAGE   XCTEST_TEST_PACKAGE   XCTEST_UI_TEST_PACKAGE
            APPIUM_JAVA_JUNIT_TEST_SPEC   APPIUM_JAVA_TESTNG_TEST_SPEC   APPIUM_PYTHON_TEST_SPEC
            APPIUM_NODE_TEST_SPEC   APPIUM_RUBY_TEST_SPEC   APPIUM_WEB_JAVA_JUNIT_TEST_SPEC
            APPIUM_WEB_JAVA_TESTNG_TEST_SPEC   APPIUM_WEB_PYTHON_TEST_SPEC   APPIUM_WEB_NODE_TEST_SPEC
            APPIUM_WEB_RUBY_TEST_SPEC   INSTRUMENTATION_TEST_SPEC   XCTEST_UI_TEST_SPEC    If you call
            CreateUpload with WEB_APP specified, AWS Device Farm throws an ArgumentException error.
        content_type(Text, optional): The upload's content type (for example, application/octet-stream). Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.devicefarm.upload.present:
                - name: value
                - project_arn: value
                - type_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.devicefarm.upload.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.devicefarm.get_upload(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.devicefarm.create_upload(
                ctx,
                
                
                **{"Name": name, "projectArn": project_arn, "type": type_, "contentType": content_type}
            )
            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.devicefarm.get_upload(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an upload given the upload ARN.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        arn(Text): Represents the Amazon Resource Name (ARN) of the Device Farm upload to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

