package v1

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

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

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

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

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

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