package ingest

import (
	"context"
	"time"

	"github.com/tech/sendico/edge/callbacks/internal/events"
	"github.com/tech/sendico/edge/callbacks/internal/storage"
	"github.com/tech/sendico/edge/callbacks/internal/subscriptions"
	mb "github.com/tech/sendico/pkg/messaging/broker"
	"github.com/tech/sendico/pkg/mlogger"
)

// Observer captures ingest metrics.
type Observer interface {
	ObserveIngest(result string, duration time.Duration)
}

// Dependencies configure the ingest service.
type Dependencies struct {
	Logger       mlogger.Logger
	Broker       mb.Broker
	Events       events.Service
	Resolver     subscriptions.Resolver
	InboxRepo    storage.InboxRepo
	TaskRepo     storage.TaskRepo
	TaskDefaults storage.TaskDefaults
	Observer     Observer
}

// Service runs ingest workers.
type Service interface {
	Start(ctx context.Context)
	Stop()
}

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