package config

import (
	"log"

	"github.com/joho/godotenv"
)

// AppConfig contains application configuration
var AppConfig Config

// Load application configuration
func Load() error {

	// load .env file
	err := godotenv.Load()

	if err != nil {
		log.Println(".env file not presented. Retrieving configuration from environment variables")
	}

	AppConfig = Config{
		
		Service: Service{
			// 9000 DEFAULT FOR DEV ENVIRONMENT
			Port:        getEnv("NOVATECH_SERVICE_PORT", "9000"),
			Environment: getEnv("NOVATECH_SERVICE_ENVIRONMENT", "DEV"),
		},
		AdminService: Service{
			// 8080 DEFAULT FOR DEV ENVIRONMENT
			Port:        getEnv("NOVATECH_ADMIN_SERVICE_PORT", "8080"),
			Environment: getEnv("NOVATECH_ADMIN_SERVICE_ENVIRONMENT", "DEV"),
		},
		Database: Database{
			UserName:         mustGetEnv("NOVATECH_DATABASE_USERNAME"),
			Password:         mustGetEnv("NOVATECH_DATABASE_PASSWORD"),
			DatabaseName:             mustGetEnv("NOVATECH_DATABASE_NAME"),
			HostName:          mustGetEnv("NOVATECH_DATABASE_ADDRESS"),
			Port:             mustGetEnv("NOVATECH_DATABASE_PORT"),
			
		},
		
	}

	return nil
}
