package main

import (
        "fmt"
        "log"
        "net/http"
        "os"
        "os/signal"
        "syscall"

        "pool-stats/database"
        "pool-stats/ingest"
        "pool-stats/web"
)

func main() {
        db, err := database.InitDatabase()
        if err != nil {
                log.Fatalf("Failed to initialize database: %v", err)
        }
        defer db.Close()

        database.PrintAllHashes(db)

        go ingest.WatchAndIngest(db)

        go func() {
                handlers := database.Handlers{DB: db}
                http.HandleFunc("/", handlers.IndexHandler)
                fmt.Println("Listening on :8081")
                log.Fatal(http.ListenAndServe(":8081", nil))
        }()

        fmt.Println("Waiting for ctrl-c")
        sigs := make(chan os.Signal, 1)
        signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
        <-sigs
}
