package config

import (
	"os"
	"strconv"
)

type Config struct {
	Port         int
	DatabasePath string
	RateLimit    int
	APIKey       string
	SyncInterval string
	LogLevel     string
}

func Load() *Config {
	c := &Config{
		Port:         3333,
		DatabasePath: "data/sentinela.db",
		RateLimit:    100,
		SyncInterval: "30m",
		LogLevel:     "info",
	}
	if v := os.Getenv("PORT"); v != "" {
		if n, err := strconv.Atoi(v); err == nil {
			c.Port = n
		}
	}
	if v := os.Getenv("DATABASE_PATH"); v != "" {
		c.DatabasePath = v
	}
	if v := os.Getenv("RATE_LIMIT"); v != "" {
		if n, err := strconv.Atoi(v); err == nil {
			c.RateLimit = n
		}
	}
	if v := os.Getenv("API_KEY"); v != "" {
		c.APIKey = v
	}
	if v := os.Getenv("SYNC_INTERVAL"); v != "" {
		c.SyncInterval = v
	}
	if v := os.Getenv("LOG_LEVEL"); v != "" {
		c.LogLevel = v
	}
	return c
}
