package bootstate

import (
	"database/sql"

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

// BootstrapStateStoreImpl is the concrete runtimeports.BootstrapStateStore. It
// delegates each method to the canonical bootstate function of the same name. It
// carries no logic and no state of its own: behavior is byte-for-byte identical
// to calling the bootstate function directly. Every wrapped function takes a
// *sql.DB (the _System_BootstrapState table is the only state), so the struct
// binds no per-call dependency and a zero value is fully usable.
//
// The port interface lives in db/pkg/runtimeports. Hosting the concrete impl
// here (next to the functions it wraps) lets the control-plane composition roots
// — the runtime wiring AND the control-plane test wiring — construct it without
// any edge to backend (PR2 Step 2).
type BootstrapStateStoreImpl struct{}

// NewBootstrapStateStoreImpl returns a BootstrapStateStoreImpl. Intended for
// composition-root wiring.
func NewBootstrapStateStoreImpl() BootstrapStateStoreImpl {
	return BootstrapStateStoreImpl{}
}

// Compile-time assertion that the impl satisfies the runtimeports port.
var _ runtimeports.BootstrapStateStore = BootstrapStateStoreImpl{}

// ClassifyControlPlaneAutoStart delegates to bootstate.ClassifyControlPlaneAutoStart.
func (BootstrapStateStoreImpl) ClassifyControlPlaneAutoStart(rawDB *sql.DB) (contractcontrolplane.ControlPlaneAutoStartDecision, error) {
	return ClassifyControlPlaneAutoStart(rawDB)
}

// MarkControlPlaneApplyAllRunning delegates to bootstate.MarkControlPlaneApplyAllRunning.
func (BootstrapStateStoreImpl) MarkControlPlaneApplyAllRunning(rawDB *sql.DB) error {
	return MarkControlPlaneApplyAllRunning(rawDB)
}

// MarkControlPlaneApplyAllCompleted delegates to bootstate.MarkControlPlaneApplyAllCompleted.
func (BootstrapStateStoreImpl) MarkControlPlaneApplyAllCompleted(rawDB *sql.DB) error {
	return MarkControlPlaneApplyAllCompleted(rawDB)
}

// MarkControlPlaneApplyAllFailed delegates to bootstate.MarkControlPlaneApplyAllFailed.
func (BootstrapStateStoreImpl) MarkControlPlaneApplyAllFailed(rawDB *sql.DB, applyErr error) error {
	return MarkControlPlaneApplyAllFailed(rawDB, applyErr)
}

// IsControlPlaneApplyAllFinalizationRecoverable delegates to
// bootstate.IsControlPlaneApplyAllFinalizationRecoverable.
func (BootstrapStateStoreImpl) IsControlPlaneApplyAllFinalizationRecoverable(rawDB *sql.DB) (bool, error) {
	return IsControlPlaneApplyAllFinalizationRecoverable(rawDB)
}

// MarkControlPlaneApplyAllFinalizationReady delegates to
// bootstate.MarkControlPlaneApplyAllFinalizationReady.
func (BootstrapStateStoreImpl) MarkControlPlaneApplyAllFinalizationReady(rawDB *sql.DB) error {
	return MarkControlPlaneApplyAllFinalizationReady(rawDB)
}

// MarkControlPlaneApplyAllInvalidated delegates to bootstate.MarkControlPlaneApplyAllInvalidated.
func (BootstrapStateStoreImpl) MarkControlPlaneApplyAllInvalidated(rawDB *sql.DB, operation string) error {
	return MarkControlPlaneApplyAllInvalidated(rawDB, operation)
}

// IsConnectorPushLegacyMirrorBackfillCompleted delegates to bootstate.IsConnectorPushLegacyMirrorBackfillCompleted.
func (BootstrapStateStoreImpl) IsConnectorPushLegacyMirrorBackfillCompleted(rawDB *sql.DB) (bool, error) {
	return IsConnectorPushLegacyMirrorBackfillCompleted(rawDB)
}

// IsWebhookSecretKeyReadProtectionBackfillCompleted delegates to bootstate.IsWebhookSecretKeyReadProtectionBackfillCompleted.
func (BootstrapStateStoreImpl) IsWebhookSecretKeyReadProtectionBackfillCompleted(rawDB *sql.DB) (bool, error) {
	return IsWebhookSecretKeyReadProtectionBackfillCompleted(rawDB)
}

// IsConnectorEventEnqueueOrdinalBackfillCompleted delegates to bootstate.IsConnectorEventEnqueueOrdinalBackfillCompleted.
func (BootstrapStateStoreImpl) IsConnectorEventEnqueueOrdinalBackfillCompleted(rawDB *sql.DB) (bool, error) {
	return IsConnectorEventEnqueueOrdinalBackfillCompleted(rawDB)
}

// IsConnectorEventSourceLaneBackfillCompleted delegates to bootstate.IsConnectorEventSourceLaneBackfillCompleted.
func (BootstrapStateStoreImpl) IsConnectorEventSourceLaneBackfillCompleted(rawDB *sql.DB) (bool, error) {
	return IsConnectorEventSourceLaneBackfillCompleted(rawDB)
}

// IsListViewLegacyCutoverCompleted delegates to bootstate.IsListViewLegacyCutoverCompleted.
func (BootstrapStateStoreImpl) IsListViewLegacyCutoverCompleted(rawDB *sql.DB) (bool, error) {
	return IsListViewLegacyCutoverCompleted(rawDB)
}

// MarkConnectorPushLegacyMirrorBackfillCompleted delegates to bootstate.MarkConnectorPushLegacyMirrorBackfillCompleted.
func (BootstrapStateStoreImpl) MarkConnectorPushLegacyMirrorBackfillCompleted(rawDB *sql.DB) error {
	return MarkConnectorPushLegacyMirrorBackfillCompleted(rawDB)
}

// MarkWebhookSecretKeyReadProtectionBackfillCompleted delegates to bootstate.MarkWebhookSecretKeyReadProtectionBackfillCompleted.
func (BootstrapStateStoreImpl) MarkWebhookSecretKeyReadProtectionBackfillCompleted(rawDB *sql.DB) error {
	return MarkWebhookSecretKeyReadProtectionBackfillCompleted(rawDB)
}

// MarkConnectorEventEnqueueOrdinalBackfillCompleted delegates to bootstate.MarkConnectorEventEnqueueOrdinalBackfillCompleted.
func (BootstrapStateStoreImpl) MarkConnectorEventEnqueueOrdinalBackfillCompleted(rawDB *sql.DB) error {
	return MarkConnectorEventEnqueueOrdinalBackfillCompleted(rawDB)
}

// MarkConnectorEventSourceLaneBackfillCompleted delegates to bootstate.MarkConnectorEventSourceLaneBackfillCompleted.
func (BootstrapStateStoreImpl) MarkConnectorEventSourceLaneBackfillCompleted(rawDB *sql.DB) error {
	return MarkConnectorEventSourceLaneBackfillCompleted(rawDB)
}

// MarkListViewLegacyCutoverCompleted delegates to bootstate.MarkListViewLegacyCutoverCompleted.
func (BootstrapStateStoreImpl) MarkListViewLegacyCutoverCompleted(rawDB *sql.DB) error {
	return MarkListViewLegacyCutoverCompleted(rawDB)
}
