package main

import (
	"bpmsapi/router"
	"bpmsapi/util"
	"flag"
	"log"
	"os"
	"strings"
)

func main() {

	runEnv := flag.String("environment", "", "Running environment")
	databaseUrl := flag.String("connection", "", "Database URL")
	//os.Setenv("APP_ENV", "test")
	flag.Parse()
	//fmt.Print(*runEnv)
	/*if os.Getenv("CONFIG") != "" {
		conf := strings.Split(os.Getenv("CONFIG"), ";")
		log.Print(conf)
		if len(conf) >= 3 {
			log.Print(conf[1])
			os.Setenv("APP_ENV", conf[1])
			os.Setenv("DB_CONFIG", conf[0])
			os.Setenv("PORT", conf[2])
		}
	}*/
	if *runEnv != "" {
		os.Setenv("APP_ENV", *runEnv)
	}
	if *databaseUrl != "" {
		os.Setenv("DB_CONFIG", *databaseUrl)
	}
	util.Environment = os.Getenv("APP_ENV")
	util.Port = os.Getenv("PORT")
	if util.Port == "" {
		util.Port = ":8082"
	}
	log.Print(os.Getenv("APP_ENV"))
	log.Print(os.Getenv("PORT"))
	log.Print(os.Getenv("DB_CONFIG"))
	router, f := router.InitRouters()
	defer f.Close()
	if strings.ToLower(util.Environment) == "test" {
		//router.RunTLS(port, "/home/hygeiasslcertificate/hygeialaundry_com.crt", "/home/hygeiasslcertificate/hygeialaundry.key")
		router.Run(util.Port)
		//router.RunTLS(util.Port, "/home/sslcertificated/sivakasicrackers_co_in.crt", "/home/sslcertificated/HSSL-6140488322aaf.key")
	} else if strings.ToLower(util.Environment) == "production" {
		router.RunTLS(util.Port, "/home/hygeiasslcertificate/hygeialaundry_com.crt", "/home/hygeiasslcertificate/hygeialaundry.key")
		//router.RunTLS(port, "/home/sslcertificated/sivakasicrackers_co_in.crt", "/home/sslcertificated/HSSL-6140488322aaf.key")
	} else if strings.ToLower(util.Environment) == "local" {
		//router.RunTLS(port, "/home/sslcertificated/sivakasicrackers_co_in.crt", "/home/sslcertificated/HSSL-6140488322aaf.key")
		//fmt.Print(util.Environment)
		router.Run(util.Port)
	}
}
