package main

import (
	"log"

	"github.com/jobs-scraper/cron"
	"github.com/jobs-scraper/infrastructure"
	"github.com/joho/godotenv"
)

func main() {
	// Try to load .local.env first, then fallback to .env
	if err := godotenv.Load("../../.local.env"); err != nil {
		log.Println("No .local.env file found, trying .env")
		if err := godotenv.Load("../../.env"); err != nil {
			log.Println("No .env file found, using system environment variables")
		}
	}

	dbConfig := infrastructure.LoadConfigFromEnv()

	db, err := infrastructure.NewConnection(dbConfig)
	if err != nil {
		log.Fatal("Error connecting to db")
	}

	err = db.Ping()
	if err != nil {
		log.Fatal("Error pinging db")
	}

	log.Println("Successfully connected to db")

	analyzer := cron.NewJobAnalyzer(db)
	
	if err := analyzer.AnalyzeJobs(); err != nil {
		log.Fatalf("Error analyzing jobs: %v", err)
	}

	log.Println("Job analysis completed successfully")
}
