package reliable

import (
	pmessaging "github.com/tech/sendico/pkg/messaging"
	"github.com/tech/sendico/pkg/mlogger"
	"github.com/tech/sendico/pkg/model"
)

func NewReliableProducerFromConfig(logger mlogger.Logger, direct pmessaging.Producer, outbox OutboxStore, driverSettings model.SettingsT, opts ...Option) (*ReliableProducer, Settings, error) {
	settings, err := ParseSettings(driverSettings)
	if err != nil {
		return nil, Settings{}, err
	}
	if !settings.Enabled {
		return nil, settings, nil
	}

	combined := []Option{
		WithBatchSize(settings.BatchSize),
		WithPollInterval(settings.PollInterval()),
		WithMaxAttempts(settings.MaxAttempts),
	}
	combined = append(combined, opts...)

	return NewReliableProducer(logger, direct, outbox, combined...), settings, nil
}
