package main

import (
	"flag"
	"imooc.com/aiworkc/internal/handler/ws"
	"sync"

	"imooc.com/aiworkc/internal/config"
	"imooc.com/aiworkc/internal/handler/api"
	"imooc.com/aiworkc/internal/svc"
	"imooc.com/aiworkc/pkg/conf"
)

type Serve interface {
	Run() error
}

const (
	Api = "api"

	// add other module
)

var (
	configFile = flag.String("f", "./etc/api.yaml", "the config file")
	modeType   = flag.String("m", "api", "server run mod")

	sw sync.WaitGroup
)

func main() {
	flag.Parse()

	var cfg config.Config
	conf.MustLoad(*configFile, &cfg)

	sw.Add(1)
	go func() {
		defer sw.Done()
		svc, err := svc.NewServiceContext(cfg)
		if err != nil {
			panic(err)
		}
		srv := api.NewHandle(svc)
		srv.Run()
	}()
	sw.Add(1)
	go func() {
		defer sw.Done()
		svc, err := svc.NewServiceContext(cfg)
		if err != nil {
			panic(err)
		}
		srv := ws.NewWs(svc)
		srv.Run()
	}()

	sw.Wait()
	//var srv Serve
	//switch *modeType {
	//case Api:
	//	srv = api.NewHandle(svc)
	//// add other module case
	//default:
	//	panic("请指定正确的服务")
	//}
	//
	//srv.Run()
}
