package main

import (
	"flag"
	"nrhe-train/api"
	"nrhe-train/conf"
	"nrhe-train/db"
	"nrhe-train/log"

	"go.uber.org/dig"
	"infish.cn/comm"
)

var confFile = flag.String("conf", "./app.yaml", "conf file")

func BuildApp() *dig.Container {

	app := dig.New()
	_ = app.Provide(func() (*conf.AppConf, error) {
		return conf.NewAppConf(*confFile)
	})

	_ = app.Provide(db.NewMongoDB)
	// _ = app.Provide(db.NewRedisClient)
	// _ = app.Provide(bus.NewNatsBus)

	_ = app.Provide(api.NewHttpService)

	return app
}

func main() {
	comm.AppMongoMiration()
	flag.Parse()
	app := BuildApp()
	err := app.Invoke(func(svc *api.Service) error {
		// go bus.Run(nil)

		svc.Run()
		return nil
	})

	if err != nil {
		log.Errorf("the pink service start fail %+v", err)
		panic(err)
	}
}
