package ostate

import (
	"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/agg"

	"github.com/tech/sendico/pkg/mlogger"
	"go.uber.org/zap"
)

// StateMachine is the single source of truth for orchestration-v2 state transitions.
type StateMachine interface {
	CanTransitionAggregate(from, to agg.State) bool
	CanTransitionStep(from, to agg.StepState) bool
	EnsureAggregateTransition(from, to agg.State) error
	EnsureStepTransition(from, to agg.StepState) error
	IsAggregateTerminal(state agg.State) bool
	IsStepTerminal(state agg.StepState) bool
}

// Dependencies configures state-machine integrations.
type Dependencies struct {
	Logger mlogger.Logger
}

func New(deps ...Dependencies) StateMachine {
	var dep Dependencies
	if len(deps) > 0 {
		dep = deps[0]
	}
	logger := dep.Logger
	if logger == nil {
		logger = zap.NewNop()
	}
	return &svc{logger: logger.Named("state_machine")}
}
