package services

import (
	"go.ipao.vip/atom"
	"go.ipao.vip/atom/container"
	"go.ipao.vip/atom/contracts"
	"go.ipao.vip/atom/opt"
	"gorm.io/gorm"
)

func Provide(opts ...opt.Option) error {
	if err := container.Container.Provide(func(
		db *gorm.DB,
		tenant *tenant,
		test *test,
		user *user,
	) (contracts.Initial, error) {
		obj := &services{
			db:     db,
			tenant: tenant,
			test:   test,
			user:   user,
		}
		if err := obj.Prepare(); err != nil {
			return nil, err
		}

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

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

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

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