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

hub.exec.boto3.client.amplify.create_app
hub.exec.boto3.client.amplify.delete_app
hub.exec.boto3.client.amplify.get_app
hub.exec.boto3.client.amplify.list_apps
hub.exec.boto3.client.amplify.update_app
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, description: Text = None, repository: Text = None, platform: Text = None, iam_service_role_arn: Text = None, oauth_token: Text = None, access_token: Text = None, environment_variables: Dict = None, enable_branch_auto_build: bool = None, enable_branch_auto_deletion: bool = None, enable_basic_auth: bool = None, basic_auth_credentials: Text = None, custom_rules: List = None, tags: Dict = None, build_spec: Text = None, custom_headers: Text = None, enable_auto_branch_creation: bool = None, auto_branch_creation_patterns: List = None, auto_branch_creation_config: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a new Amplify app.

    Args:
        name(Text):  The name for an Amplify app.
        description(Text, optional):  The description for an Amplify app. Defaults to None.
        repository(Text, optional):  The repository for an Amplify app. Defaults to None.
        platform(Text, optional):  The platform or framework for an Amplify app. Defaults to None.
        iam_service_role_arn(Text, optional):  The AWS Identity and Access Management (IAM) service role for an Amplify app. Defaults to None.
        oauth_token(Text, optional):  The OAuth token for a third-party source control system for an Amplify app. The OAuth token is
            used to create a webhook and a read-only deploy key. The OAuth token is not stored. Defaults to None.
        access_token(Text, optional):  The personal access token for a third-party source control system for an Amplify app. The
            personal access token is used to create a webhook and a read-only deploy key. The token is not
            stored. Defaults to None.
        environment_variables(Dict, optional):  The environment variables map for an Amplify app. Defaults to None.
        enable_branch_auto_build(bool, optional):  Enables the auto building of branches for an Amplify app. Defaults to None.
        enable_branch_auto_deletion(bool, optional):  Automatically disconnects a branch in the Amplify Console when you delete a branch from your
            Git repository. Defaults to None.
        enable_basic_auth(bool, optional):  Enables basic authorization for an Amplify app. This will apply to all branches that are part
            of this app. Defaults to None.
        basic_auth_credentials(Text, optional):  The credentials for basic authorization for an Amplify app. Defaults to None.
        custom_rules(List, optional):  The custom rewrite and redirect rules for an Amplify app. Defaults to None.
        tags(Dict, optional):  The tag for an Amplify app. Defaults to None.
        build_spec(Text, optional):  The build specification (build spec) for an Amplify app. Defaults to None.
        custom_headers(Text, optional): The custom HTTP headers for an Amplify app. Defaults to None.
        enable_auto_branch_creation(bool, optional):  Enables automated branch creation for an Amplify app. Defaults to None.
        auto_branch_creation_patterns(List, optional):  The automated branch creation glob patterns for an Amplify app. Defaults to None.
        auto_branch_creation_config(Dict, optional):  The automated branch creation configuration for an Amplify app. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.amplify.create_app(
                ctx,
                
                
                **{"Name": name, "description": description, "repository": repository, "platform": platform, "iamServiceRoleArn": iam_service_role_arn, "oauthToken": oauth_token, "accessToken": access_token, "environmentVariables": environment_variables, "enableBranchAutoBuild": enable_branch_auto_build, "enableBranchAutoDeletion": enable_branch_auto_deletion, "enableBasicAuth": enable_basic_auth, "basicAuthCredentials": basic_auth_credentials, "customRules": custom_rules, "tags": tags, "buildSpec": build_spec, "customHeaders": custom_headers, "enableAutoBranchCreation": enable_auto_branch_creation, "autoBranchCreationPatterns": auto_branch_creation_patterns, "autoBranchCreationConfig": auto_branch_creation_config}
            )
            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.amplify.get_app(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, app_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes an existing Amplify app specified by an app ID.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        app_id(Text):  The unique ID for an Amplify app.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

