package tenant

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

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

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

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

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

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

		return obj, nil
	}); err != nil {
		return err
	}
	if err := container.Container.Provide(func(
		content *content,
		contentAdmin *contentAdmin,
		me *me,
		middlewares *middlewares.Middlewares,
		order *order,
		orderAdmin *orderAdmin,
		orderMe *orderMe,
		tenantInviteAdmin *tenantInviteAdmin,
		tenantJoinAdmin *tenantJoinAdmin,
		tenantUserAdmin *tenantUserAdmin,
	) (contracts.HttpRoute, error) {
		obj := &Routes{
			content:           content,
			contentAdmin:      contentAdmin,
			me:                me,
			middlewares:       middlewares,
			order:             order,
			orderAdmin:        orderAdmin,
			orderMe:           orderMe,
			tenantInviteAdmin: tenantInviteAdmin,
			tenantJoinAdmin:   tenantJoinAdmin,
			tenantUserAdmin:   tenantUserAdmin,
		}
		if err := obj.Prepare(); err != nil {
			return nil, err
		}

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

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

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

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