package automationtesting

import (
	"context"
	"testing"

	"github.com/nexuscrm/shared/pkg/models"
)

func TestNewRig_NoOptions_ReturnsConfiguredHarness(t *testing.T) {
	rig := NewRig()
	if rig == nil {
		t.Fatal("NewRig() returned nil; expected a Rig with default-wired executor")
	}
	if rig.executor == nil {
		t.Fatal("Rig.executor is nil; FlowExecutor construction failed under default options")
	}
}

func TestNewRig_WithFlowVersionResolver_RoutesIntoExecutor(t *testing.T) {
	calls := 0
	resolver := func(ctx context.Context, apiName string, user *models.UserSession) (*models.FlowVersion, error) {
		calls++
		return &models.FlowVersion{Id: "fv-test", DefinitionId: "fd-test"}, nil
	}

	rig := NewRig(WithFlowVersionResolver(resolver))
	if rig == nil {
		t.Fatal("NewRig(WithFlowVersionResolver) returned nil")
	}

	// Scope: this test asserts only that the bridge builds the executor
	// without panicking when WithFlowVersionResolver is applied. End-to-end
	// "the resolver actually fires" assertions land in the first scenario
	// PR that grows Rig with methods driving the runtime — the resolver
	// fires only at runtime lookup, which Rig has no method to invoke yet.
	if rig.executor == nil {
		t.Fatal("Rig.executor is nil; FlowExecutor construction failed when WithFlowVersionResolver was applied")
	}
	if calls != 0 {
		t.Fatalf("resolver called %d times during construction; expected 0 (resolver fires only at runtime lookup)", calls)
	}
}
