package packs

import (
	"context"
	"testing"
	"time"

	cp "github.com/pingcap-inc/nexuscrm-contract/pkg/controlplane"
)

func testComponentManagedLifecycleRegistration(t *testing.T, kind cp.ComponentKind, table string) cp.ComponentManagedLifecycleRegistration {
	t.Helper()
	registration, err := cp.NewComponentManagedLifecycleRegistration(cp.ComponentManagedLifecycleRegistrationSpec{
		Kind:    kind,
		ReadSet: []cp.ComponentReadSurface{{Table: table, Fact: "managed rows"}},
		Capabilities: []cp.ComponentManagedCapability{
			cp.ComponentManagedCapabilityTargetSerialization,
			cp.ComponentManagedCapabilityStructuredMutation,
			cp.ComponentManagedCapabilityEvidence,
			cp.ComponentManagedCapabilityFreshProjection,
		},
		TransactionMode: cp.ComponentManagedTransactionPessimisticReadCommitted,
		Budget: cp.ComponentManagedBudget{
			MaxTargets: 10, MaxCurrentItems: 10, MaxDesiredItems: 10, MaxDeltaRows: 10,
			MaxMutationBytes: 1024, MaxMutationStatements: 10, MaxBatchRows: 10,
			MaxEvidenceWrites: 1, MaxEffectCalls: 1,
			MaxLockWait: time.Second, MaxElapsed: time.Second, MaxAttempts: 3,
		},
		Lifecycle: cp.ComponentManagedLifecycleProvider{
			Plan: func(context.Context, cp.ComponentManagedScope, cp.ComponentManagedLifecycleRequest, cp.ComponentManagedReadStore) (cp.ComponentManagedPlan, error) {
				return cp.ComponentManagedPlan{}, nil
			},
			Mutate: func(context.Context, cp.ComponentManagedScope, cp.ComponentManagedLifecycleRequest, cp.ComponentManagedPlan, cp.ComponentManagedMutationStore) (cp.ComponentManagedMutationResult, error) {
				return cp.ComponentManagedMutationResult{}, nil
			},
			Project: func(context.Context, cp.ComponentManagedScope, cp.ComponentManagedLifecycleRequest, cp.ComponentManagedReadStore) (cp.ComponentManagedProjection, error) {
				return cp.ComponentManagedProjection{}, nil
			},
		},
	})
	if err != nil {
		t.Fatal(err)
	}
	return registration
}
