package config

import (
	alchemyConfig "github.com/AlchemyTelcoSolutions/go-packages/pkg/config"
)

type AppConfig interface {
	LoadConfigs() error
	GetConfigurations() *Config
}

// New return  a New Config
func New() *Config {
	return &Config{}
}

// GetConfigurations return the struct configuration values
func (c *Config) GetConfigurations() *Config {
	return c
}

// LoadConfigs - loads the configuration, stored on the config files
func (c *Config) LoadConfigs() error {
	baseConfig := alchemyConfig.New().SetConfigImpl(c)
	err := baseConfig.LoadConfigs(c)
	if err != nil {
		return err
	}
	return nil
}

// SetDefaults set default values for config variables if are not set in config file
func (c *Config) SetDefaults() alchemyConfig.ConfigMap {
	defaults := make(alchemyConfig.ConfigMap)
	// http_server
	defaults["http_server.enabled"] = true
	defaults["http_server.port"] = 3001
	defaults["http_server.allowed_origins"] = []string{
		"*",
	}

	defaults["http_server.api_prefix"] = "/callisto"
	//Proxy
	defaults["http_server.proxy.enabled"] = true
	defaults["http_server.proxy.paths"] = map[string]string{}

	// callisto so grpc
	defaults["callisto_so.enabled"] = false
	return defaults
}

// AWSLocalMap is a function to map secrets into a config structure
func (c *Config) AWSLocalMap() alchemyConfig.ConfigMap {
	mapConfig := make(alchemyConfig.ConfigMap)
	// in case ENVIRONMENT_CONFIG has more than one secret id (comma separated) can make the local mapping adding the secretid as prefix
	// this is one example to map the key in secrets "username" and "password" from the secret is "database "to db.db_user and db password
	// mapConfig["database.username"] = "db.db_user"
	// mapConfig["database.password"] = "db.db_password"
	return mapConfig
}
