package main

import (
	"log"
	"os"

	"weatherstation/core/internal/config"
	"weatherstation/core/internal/data"
	"weatherstation/core/internal/server"
)

func main() {
	cfg := config.Load()
	_ = data.DB()
	r := server.NewRouter(server.Options{
		UIServeDir:   cfg.UIServeDir,
		BigscreenDir: cfg.BigscreenDir,
		TemplateDir:  cfg.TemplateDir,
		StaticDir:    cfg.StaticDir,
		EnableCORS:   cfg.DevEnableCORS,
	})

	addr := cfg.Addr
	if env := os.Getenv("PORT"); env != "" {
		addr = ":" + env
	}

	log.Printf("core-api listening on %s", addr)
	if err := r.Run(addr); err != nil {
		log.Fatal(err)
	}
}
