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

hub.exec.boto3.client.amplify.create_branch
hub.exec.boto3.client.amplify.delete_branch
hub.exec.boto3.client.amplify.get_branch
hub.exec.boto3.client.amplify.list_branches
hub.exec.boto3.client.amplify.update_branch
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, app_id: Text, branch_name: Text, description: Text = None, stage: Text = None, framework: Text = None, enable_notification: bool = None, enable_auto_build: bool = None, environment_variables: Dict = None, basic_auth_credentials: Text = None, enable_basic_auth: bool = None, enable_performance_mode: bool = None, tags: Dict = None, build_spec: Text = None, ttl: Text = None, display_name: Text = None, enable_pull_request_preview: bool = None, pull_request_environment_name: Text = None, backend_environment_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Creates a new branch for an Amplify app.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        app_id(Text):  The unique ID for an Amplify app.
        branch_name(Text):  The name for the branch.
        description(Text, optional):  The description for the branch. Defaults to None.
        stage(Text, optional):  Describes the current stage for the branch. Defaults to None.
        framework(Text, optional):  The framework for the branch. Defaults to None.
        enable_notification(bool, optional):  Enables notifications for the branch. Defaults to None.
        enable_auto_build(bool, optional):  Enables auto building for the branch. Defaults to None.
        environment_variables(Dict, optional):  The environment variables for the branch. Defaults to None.
        basic_auth_credentials(Text, optional):  The basic authorization credentials for the branch. Defaults to None.
        enable_basic_auth(bool, optional):  Enables basic authorization for the branch. Defaults to None.
        enable_performance_mode(bool, optional): Enables performance mode for the branch. Performance mode optimizes for faster hosting
            performance by keeping content cached at the edge for a longer interval. When performance mode
            is enabled, hosting configuration or code changes can take up to 10 minutes to roll out. Defaults to None.
        tags(Dict, optional):  The tag for the branch. Defaults to None.
        build_spec(Text, optional):  The build specification (build spec) for the branch. Defaults to None.
        ttl(Text, optional):  The content Time To Live (TTL) for the website in seconds. Defaults to None.
        display_name(Text, optional):  The display name for a branch. This is used as the default domain prefix. Defaults to None.
        enable_pull_request_preview(bool, optional):  Enables pull request previews for this branch. Defaults to None.
        pull_request_environment_name(Text, optional):  The Amplify environment name for the pull request. Defaults to None.
        backend_environment_arn(Text, optional):  The Amazon Resource Name (ARN) for a backend environment that is part of an Amplify app. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.amplify.create_branch(
                ctx,
                
                
                **{"appId": app_id, "branchName": branch_name, "description": description, "stage": stage, "framework": framework, "enableNotification": enable_notification, "enableAutoBuild": enable_auto_build, "environmentVariables": environment_variables, "basicAuthCredentials": basic_auth_credentials, "enableBasicAuth": enable_basic_auth, "enablePerformanceMode": enable_performance_mode, "tags": tags, "buildSpec": build_spec, "ttl": ttl, "displayName": display_name, "enablePullRequestPreview": enable_pull_request_preview, "pullRequestEnvironmentName": pull_request_environment_name, "backendEnvironmentArn": backend_environment_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.amplify.get_branch(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, app_id: Text, branch_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
     Deletes a branch for an Amplify app.

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

