package reqval

import (
	"github.com/tech/sendico/pkg/mlogger"
	"go.mongodb.org/mongo-driver/v2/bson"
	"go.uber.org/zap"
)

// Validator validates execute-payment inputs and returns a normalized context.
type Validator interface {
	Validate(req *Req) (*Ctx, error)
}

// Req is the execute-payment request shape used by the validator module.
// It is intentionally transport-agnostic, so it can be mapped from proto later.
type Req struct {
	Meta             *Meta
	QuotationRef     string
	ClientPaymentRef string
}

// Meta carries organization and trace context fields required for validation.
type Meta struct {
	OrganizationRef string
	Trace           *Trace
}

// Trace carries trace-bound idempotency key for execution requests.
type Trace struct {
	IdempotencyKey string
}

// Ctx is the normalized output used by downstream execute-payment flow.
type Ctx struct {
	OrganizationRef  string
	OrganizationID   bson.ObjectID
	IdempotencyKey   string
	QuotationRef     string
	ClientPaymentRef string
}

// Dependencies configures request validator integrations.
type Dependencies struct {
	Logger mlogger.Logger
}

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