package jobs

import (
	"quyun/providers/ali"
	"quyun/providers/app"
	"quyun/providers/job"

	"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,
	) (contracts.Initial, error) {
		obj := &BalancePayNotifyWorker{}
		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 := &CronJob{}
		if err := obj.Prepare(); err != nil {
			return nil, err
		}

		container.Later(func() error { return __job.AddPeriodicJobs(obj) })

		return obj, nil
	}, atom.GroupInitial); err != nil {
		return err
	}
	if err := container.Container.Provide(func(
		__job *job.Job,
	) (contracts.Initial, error) {
		obj := &SortWorker{}
		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,
		app *app.Config,
		job *job.Job,
		oss *ali.OSSClient,
	) (contracts.Initial, error) {
		obj := &DownloadFromAliOSSWorker{
			app: app,
			job: job,
			oss: oss,
		}
		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,
		app *app.Config,
		job *job.Job,
		oss *ali.OSSClient,
	) (contracts.Initial, error) {
		obj := &PublishDraftPostsWorker{
			app: app,
			job: job,
			oss: oss,
		}
		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 := &RemoveFileWorker{}
		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,
		app *app.Config,
		job *job.Job,
	) (contracts.Initial, error) {
		obj := &VideoCutWorker{
			app: app,
			job: job,
		}
		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,
		app *app.Config,
		job *job.Job,
		oss *ali.OSSClient,
	) (contracts.Initial, error) {
		obj := &VideoExtractHeadImageWorker{
			app: app,
			job: job,
			oss: oss,
		}
		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,
		app *app.Config,
		job *job.Job,
		oss *ali.OSSClient,
	) (contracts.Initial, error) {
		obj := &VideoStoreShortWorker{
			app: app,
			job: job,
			oss: oss,
		}
		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 := &WechatPayNotifyWorker{}
		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 := &WechatRefundNotifyWorker{}
		if err := river.AddWorkerSafely(__job.Workers, obj); err != nil {
			return nil, err
		}

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