package jobs

import (
	"quyun/v2/providers/job"
	"quyun/v2/providers/storage"

	"github.com/riverqueue/river"
	"go.ipao.vip/atom"
	"go.ipao.vip/atom/container"
	"go.ipao.vip/atom/contracts"
	"go.ipao.vip/atom/opt"
)

func Provide(opts ...opt.Option) error {
	if err := container.Container.Provide(func(
		__job *job.Job,
		storage *storage.Storage,
	) (contracts.Initial, error) {
		obj := &MediaProcessWorker{
			storage: storage,
		}
		if err := river.AddWorkerSafely(__job.Workers, obj); err != nil {
			return nil, err
		}

		return obj, nil
	}, atom.GroupInitial); err != nil {
		return err
	}
	if err := container.Container.Provide(func(
		__job *job.Job,
	) (contracts.Initial, error) {
		obj := &NotificationWorker{}
		if err := river.AddWorkerSafely(__job.Workers, obj); err != nil {
			return nil, err
		}

		return obj, nil
	}, atom.GroupInitial); err != nil {
		return err
	}
	return nil
}
