package delivery

import (
	"context"
	"time"

	"github.com/tech/sendico/edge/callbacks/internal/retry"
	"github.com/tech/sendico/edge/callbacks/internal/security"
	"github.com/tech/sendico/edge/callbacks/internal/signing"
	"github.com/tech/sendico/edge/callbacks/internal/storage"
	"github.com/tech/sendico/pkg/mlogger"
)

// Observer captures delivery metrics.
type Observer interface {
	ObserveDelivery(result string, statusCode int, duration time.Duration)
}

// Config controls delivery worker runtime.
type Config struct {
	WorkerConcurrency int
	WorkerPoll        time.Duration
	LockTTL           time.Duration
	RequestTimeout    time.Duration
	JitterRatio       float64
}

// Dependencies configure delivery dispatcher.
type Dependencies struct {
	Logger   mlogger.Logger
	Config   Config
	Tasks    storage.TaskRepo
	Retry    retry.Policy
	Security security.Validator
	Signer   signing.Signer
	Observer Observer
}

// Service executes callback delivery tasks.
type Service interface {
	Start(ctx context.Context)
	Stop()
}

// New creates delivery service.
func New(deps Dependencies) (Service, error) {
	return newService(deps)
}
