package main

import (
	"fmt"
	"log"
	"os"

	"gopkg.in/yaml.v3"
)

func DefCfg() *DefConfig {
	c := &DefConfig{}

	// server settings
	c.Server.ServDir = "factorio"
	c.Server.ServPort = 34197
	c.Server.ServCfg = "factorio/data/server-settings.json"
	c.Server.ServExec = "factorio/bin/x64/factorio"
	c.Server.WorldFile = "factorio/saves/newworld.zip"

	// factoryman settings
	c.Factoryman.UseScreen = true
	c.Factoryman.ScreenName = "factorio"
	c.Factoryman.BackupDir = "factorio/backups"
	c.Factoryman.UserName = ""
	c.Factoryman.ApiToken = ""
	return c
}
func readCfg(factCfg string) UsrConfig {
	//read config file (YAML)
	fileBytes, err := os.ReadFile(factCfg)
	if err != nil {
		fmt.Printf("Error reading config.yml file, using defaults\n")
		return UsrConfig(*DefCfg())
	}
	// return Struct
	var config UsrConfig
	err = yaml.Unmarshal(fileBytes, &config)
	if err != nil {
		log.Fatalf("Error unmarshalling YAML file: %v", err)
	}
	return config
}
