package jobs

import (
	"context"
	"testing"

	"quyun/app/models"
	"quyun/app/service/testx"
	"quyun/providers/ali"
	"quyun/providers/app"
	"quyun/providers/job"

	. "github.com/riverqueue/river"
	. "github.com/smartystreets/goconvey/convey"
	"github.com/stretchr/testify/suite"
	_ "go.ipao.vip/atom"
	"go.ipao.vip/atom/contracts"
	"go.uber.org/dig"
)

type DownloadFromAliOSSSuiteInjectParams struct {
	dig.In

	Initials []contracts.Initial `group:"initials"` // nolint:structcheck
	Job      *job.Job
	Oss      *ali.OSSClient
	App      *app.Config
}

type DownloadFromAliOSSSuite struct {
	suite.Suite

	DownloadFromAliOSSSuiteInjectParams
}

func Test_DownloadFromAliOSS(t *testing.T) {
	providers := testx.Default().With(Provide, models.Provide)

	testx.Serve(providers, t, func(p DownloadFromAliOSSSuiteInjectParams) {
		suite.Run(t, &DownloadFromAliOSSSuite{DownloadFromAliOSSSuiteInjectParams: p})
	})
}

func (t *DownloadFromAliOSSSuite) Test_Work() {
	Convey("test_work", t.T(), func() {
		Convey("step 1", func() {
			job := &Job[DownloadFromAliOSS]{
				Args: DownloadFromAliOSS{
					MediaHash: "959e5310105c96e653f10b74e5bdc36b",
				},
			}

			worker := &DownloadFromAliOSSWorker{
				oss: t.Oss,
				job: t.Job,
				app: t.App,
			}

			err := worker.Work(context.Background(), job)
			So(err, ShouldBeNil)
		})
	})
}
