package auth

import (
	"quyun/v2/app/middlewares"

	"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() (*Auth, error) {
		obj := &Auth{}

		return obj, nil
	}); err != nil {
		return err
	}
	if err := container.Container.Provide(func(
		auth *Auth,
		middlewares *middlewares.Middlewares,
	) (contracts.HttpRoute, error) {
		obj := &Routes{
			auth:        auth,
			middlewares: middlewares,
		}
		if err := obj.Prepare(); err != nil {
			return nil, err
		}

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