package appflow

import (
	"context"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/appflow"
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
	"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

func FlowStatus(ctx context.Context, conn *appflow.Appflow, id string) retry.StateRefreshFunc {
	return func() (interface{}, string, error) {
		out, err := FindFlowByARN(ctx, conn, id)

		if tfresource.NotFound(err) {
			return nil, "", nil
		}

		if err != nil {
			return nil, "", err
		}

		return out, aws.StringValue(out.FlowStatus), nil
	}
}
