package main

import (
	"strings"

	"github.com/spf13/viper"
)

func ReadConfig() (*viper.Viper, error) {
	defaults := map[string]any{
		"service_name": "PARCOURSMOB",
		"templates": map[string]any{
			"dir":        "templates/default",
			"public_dir": "template/default/public",
		},
		"server": map[string]any{
			"listen": "0.0.0.0:9000",
		},
		"identification": map[string]any{
			"sessions": map[string]any{
				"store":       "cookie",
				"session_key": "SESSION_KEY",
			},
		},
		"geo": map[string]any{
			"pelias": map[string]any{
				"url": "https://geocode.ridygo.fr",
			},
		},
	}
	v := viper.New()
	for key, value := range defaults {
		v.SetDefault(key, value)
	}
	v.SetConfigName("config")
	v.AddConfigPath(".")
	v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
	v.AutomaticEnv()
	err := v.ReadInConfig()
	return v, err
}
