// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package tpgresource

import (
	"net/url"
	"testing"
	"time"

	transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

type TestWaiter struct {
	runCount int
}

func (w *TestWaiter) State() string {
	if w.runCount == 2 {
		return "DONE"
	}
	return "RUNNING"
}

func (TestWaiter) IsRetryable(err error) bool {
	return false
}

func (TestWaiter) Error() error {
	return nil
}

func (TestWaiter) SetOp(interface{}) error {
	return nil
}

func (w *TestWaiter) QueryOp() (interface{}, error) {
	w.runCount++
	if w.runCount == 1 {
		return nil, &url.Error{
			Err: transport_tpg.TimeoutErr,
		}
	}
	return "my return value", nil
}

func (TestWaiter) OpName() string {
	return "my-operation-name"
}

func (TestWaiter) PendingStates() []string {
	return []string{}
}

func (TestWaiter) TargetStates() []string {
	return []string{"DONE"}
}

func TestOperationWait_TimeoutsShouldRetry(t *testing.T) {
	testWaiter := TestWaiter{
		runCount: 0,
	}
	err := OperationWait(&testWaiter, "my-activity", 1*time.Minute, 0*time.Second)
	if err != nil {
		t.Fatalf("unexpected error waiting for operation: got '%v', want 'nil'", err)
	}
	expectedRunCount := 2
	if testWaiter.runCount != expectedRunCount {
		t.Errorf("expected the retryFunc to be called %v time(s), instead was called %v time(s)",
			expectedRunCount, testWaiter.runCount)
	}
}
