package main

import (
	"crm-api/cmd/commands"
	"crm-api/pkg/utils"
	"fmt"
	"os"
	"runtime"
	"time"

	"github.com/urfave/cli"
)

var (
	gitCommitCode string
	buildDateTime string
	goVersion     string
)

func init() {
	locationName := utils.GetLocationName()
	if locationName != "" {
		time.Local, _ = time.LoadLocation(locationName)
	}
	runtime.GOMAXPROCS(runtime.NumCPU())
}

func main() {
	initVersion()
	app := cli.NewApp()
	app.Name = "pbx-api-gin"
	app.Usage = "A PBX Manager Server"
	app.Version = fmt.Sprintf("%s-%s-%s", buildDateTime, gitCommitCode, goVersion)
	app.Commands = []cli.Command{
		commands.CmdWeb,
		commands.CmdService,
	}
	app.Flags = []cli.Flag{
		cli.IntFlag{
			Name:  "level",
			Usage: "log level 0(panic)-6(trace), default 4(info)",
			Value: 4,
		},
		cli.BoolFlag{
			Name:  "reportCaller",
			Usage: "if true report logger caller",
		},
		cli.BoolFlag{
			Name:  "disableConsoleLog",
			Usage: "if true cancel console log",
		},
		cli.BoolFlag{
			Name:  "release",
			Usage: "if true gin set release",
		},
		cli.BoolFlag{
			Name:  "prompt",
			Usage: "if ture, prompt will show",
		},
	}
	_ = app.Run(os.Args)
}

func initVersion() {
	if gitCommitCode != "" {
		utils.VersionInstance.BuildDate = buildDateTime
		utils.VersionInstance.GoVersion = goVersion
		utils.VersionInstance.GitCommitCode = gitCommitCode
	}
}
