package controlplane

import (
	"github.com/nexuscrm/db/pkg/runtimeports"
)

// CONTROL-PLANE SEAM — control-plane imports bootstrap = ZERO (W5/S7).
//
// bootstrapStateStore is the control-plane's BootstrapStateStore port. The
// ApplyAll lifecycle path (operations.go) and the source-pack reapply path
// (source_pack_ops.go) call this port instead of the internal/bootstrap
// functions directly, so the behavioral dependency is inverted: the concrete
// implementation is constructed and injected at the composition roots
// (pkg/serverruntime, internal/setupcmd, and CP test wiring) via
// SetBootstrapStateStore — never defaulted here. The control-plane no longer
// references internal/bootstrap at all; the concrete bootstrap impl is owned by
// the backend-side wiring entrypoint (serverruntime.WireControlplaneSeams).
//
// Mandatory injection: every entry point that runs the apply/reapply path MUST
// wire this port before calling it, or the port is nil. cmd/setup and the CP
// integration tests wire via the composition roots / test wiring.
var bootstrapStateStore runtimeports.BootstrapStateStore

// SetBootstrapStateStore injects the control-plane BootstrapStateStore port.
// Intended for the composition roots (pkg/serverruntime via
// WireControlplaneSeams, internal/setupcmd, and CP test wiring), which
// construct the bootstrap implementation and inject it here so the concrete
// dependency is owned by the composition root rather than the control-plane
// apply path.
func SetBootstrapStateStore(p runtimeports.BootstrapStateStore) {
	if p == nil {
		return
	}
	bootstrapStateStore = p
}
