package app

import (
	"os"

	"github.com/spf13/cobra"
	"gitlab.com/security-rd/go-pkg/logging"
	"gitlab.com/tensorsecurity-rd/waf-console/api"
	"gitlab.com/tensorsecurity-rd/waf-console/internal/config"
)

func NewRootCommand() *cobra.Command {
	return &cobra.Command{
		Use:   "waf-console",
		Short: "Start waf-console service.",
		Args:  cobra.ExactArgs(0),
		RunE: func(cmd *cobra.Command, args []string) error {
			debugMode := os.Getenv("DEBUG_MODE")
			logging.Get().Info().Msgf("DEBUG_MODE: %s", debugMode)
			if debugMode == "true" {
				config.Conf.Debug = true
			}

			e := api.SetRouters()
			return e.Run(":8080")
		},
	}
}
