package bootstrapimpl

import (
	"context"
	"database/sql"

	"github.com/nexuscrm/db/pkg/runtimeports"
	"github.com/pingcap-inc/nexuscrm-contract/pkg/autonumberseed"
)

// AutoNumberSeederImpl is the concrete runtimeports.AutoNumberSeeder.
// It delegates each method to the canonical bootstrap function of the same
// name. It carries no logic and no state of its own: behavior is byte-for-byte
// identical to calling the bootstrap function directly. The seed/verify methods
// take a *sql.DB per call, so the struct binds no per-call dependency and is
// safe to construct once at the composition root and share.
//
// The port interface lives in pkg/serverruntime/runtimeports (a leaf package
// that imports nothing backend-internal). bootstrap is allowed to import
// runtimeports, so the concrete impl is hosted here next to the functions it
// wraps. The runtime composition root (pkg/serverruntime) constructs this and
// injects it into the control-plane consumers, which depend only on the port.
//
// The interface parameter types resolve to nexuscrm-contract/pkg/autonumberseed;
// the bootstrap AutoNumberFormatSeed / AutoNumberDeclaredSeedKey types are
// aliases of those same contract types, so the delegations type-check without
// any conversion.
type AutoNumberSeederImpl struct{}

// NewAutoNumberSeederImpl returns an AutoNumberSeederImpl. Intended for
// composition-root wiring.
func NewAutoNumberSeederImpl() AutoNumberSeederImpl {
	return AutoNumberSeederImpl{}
}

// Compile-time assertion that the bootstrap impl satisfies the runtimeports port.
var _ runtimeports.AutoNumberSeeder = AutoNumberSeederImpl{}

// SeedAutoNumberCounters delegates to bootstrap.SeedAutoNumberCounters.
func (AutoNumberSeederImpl) SeedAutoNumberCounters(ctx context.Context, rawDB *sql.DB, seedMap []autonumberseed.AutoNumberFormatSeed, scopeSourceMap map[string]string) error {
	return SeedAutoNumberCounters(ctx, rawDB, seedMap, scopeSourceMap)
}

// VerifyAutoNumberInvariants delegates to bootstrap.VerifyAutoNumberInvariants.
func (AutoNumberSeederImpl) VerifyAutoNumberInvariants(ctx context.Context, rawDB *sql.DB) error {
	return VerifyAutoNumberInvariants(ctx, rawDB)
}

// VerifyAutoNumberMetadataInvariants delegates to bootstrap.VerifyAutoNumberMetadataInvariants.
func (AutoNumberSeederImpl) VerifyAutoNumberMetadataInvariants(ctx context.Context, rawDB *sql.DB) error {
	return VerifyAutoNumberMetadataInvariants(ctx, rawDB)
}

// RegisterAutoNumberDeclaredSeeds delegates to bootstrap.RegisterAutoNumberDeclaredSeeds.
func (AutoNumberSeederImpl) RegisterAutoNumberDeclaredSeeds(keys []autonumberseed.AutoNumberDeclaredSeedKey) {
	RegisterAutoNumberDeclaredSeeds(keys)
}
