// Package sfcrm_test verifies the cross-module test seam between the
// SF-CRM scenario module and the platform runtime, via the L0 bridge
// package backend/pkg/automationtesting.
//
// Scope of this file: prove the cross-module mechanism works.
// Specifically:
//
//   - this test module (nexuscrm-tests/sf-crm) imports ONLY
//     backend/pkg/automationtesting and github.com/nexuscrm/shared/pkg/models;
//     it does not import backend/internal/... (Go's internal/ rule
//     would block that anyway, and our convention forbids it)
//   - the replace directive in go.mod resolves backend → ../../../backend
//   - automationtesting.WithFlowVersionResolver compiles and applies
//     without exposing internal types
//   - the L1 string "Lead" appears in this file but never enters
//     backend/
//
// Out of scope: actual flow trigger / execution behavior assertions.
// Those require generic rig methods on automationtesting.Rig that future
// PRs add as scenario coverage grows.
//
// Naming: this file is deliberately named seam_test.go, not
// flow_conformance_test.go. The second name implies contract-level
// coverage which one file cannot deliver — that confusion was a
// contributing factor to the PR #173 / #196 revert. New scenario
// files should describe the behavior under test, e.g.
// lead_insert_before_save_test.go, lead_update_field_default_test.go.
package sfcrm_test

import (
	"context"
	"testing"

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

func TestSeam_LeadFlowVersionResolverWiresThroughBridge(t *testing.T) {
	const sobject = "Lead"

	calls := 0
	resolver := func(ctx context.Context, apiName string, user *models.UserSession) (*models.FlowVersion, error) {
		calls++
		// Future scenarios will assert apiName matches a pack-shaped
		// trigger flow name like "Lead_AfterInsert_StampDefaults".
		// For this seam check the resolver only needs to be wired,
		// not invoked, so it returns a sentinel.
		return &models.FlowVersion{Id: "fv-seam-" + apiName}, nil
	}

	rig := automationtesting.NewRig(automationtesting.WithFlowVersionResolver(resolver))
	if rig == nil {
		t.Fatalf("automationtesting.NewRig(WithFlowVersionResolver) returned nil for %s scenarios", sobject)
	}
	if calls != 0 {
		t.Fatalf("resolver fired %d times during construction; expected 0 (resolver should fire only at runtime lookup)", calls)
	}
}
