package config

import (
	"fmt"
	"os"
	"strconv"

	"github.com/joho/godotenv"
)

var ENV string

// URLs
var BASE_URL string
const PORT = "3003"

// Auth
var JWT_SECRET string

// Logging
var LOG_TO_FILE bool

func SetConfiguration() {
	err := godotenv.Load()
	if err != nil {
		fmt.Println("no .env file found. Needs to be added to server directory.")
	}

	ENV = os.Getenv("ENV")
	if ENV != "production" && ENV != "development" {
		fmt.Println("invalid value for ENV, must be 'development' or 'production'")
		os.Exit(1)
	}

	BASE_URL = os.Getenv("BASE_URL")
	if BASE_URL == "" {
		fmt.Println("BASE_URL not provided, aborting")
		os.Exit(1)
	}

	JWT_SECRET = os.Getenv("JWT_SECRET")
	if JWT_SECRET == "" {
		fmt.Println("JWT_SECRET not provided, aborting")
		os.Exit(1)
	}

	LOG_TO_FILE, err = strconv.ParseBool(os.Getenv("LOG_TO_FILE"))
	if err != nil {
		LOG_TO_FILE = false
	}
}