package super

import (
	"quyun/v2/providers/app"
	"quyun/v2/providers/jwt"

	"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(
		app *app.Config,
		jwt *jwt.JWT,
	) (*authController, error) {
		obj := &authController{
			app: app,
			jwt: jwt,
		}

		return obj, nil
	}); err != nil {
		return err
	}
	if err := container.Container.Provide(func(
		authController *authController,
		staticController *staticController,
		tenant *tenant,
	) (contracts.HttpRoute, error) {
		obj := &Routes{
			authController:   authController,
			staticController: staticController,
			tenant:           tenant,
		}
		if err := obj.Prepare(); err != nil {
			return nil, err
		}

		return obj, nil
	}, atom.GroupRoutes); err != nil {
		return err
	}
	if err := container.Container.Provide(func() (*staticController, error) {
		obj := &staticController{}

		return obj, nil
	}); err != nil {
		return err
	}
	if err := container.Container.Provide(func() (*tenant, error) {
		obj := &tenant{}

		return obj, nil
	}); err != nil {
		return err
	}
	return nil
}
