package main

import (
	"log"
	"os"
	"os/signal"
	"syscall"

	"github.com/rjNemo/rentease/internal/cron"
)

func main() {
	scheduler := cron.New()

	scheduler.AddJob(cron.Job{
		Name:     "Monthly Booking Report",
		Schedule: "minute",
		//Schedule: "monthly",
		// Action: cron.JobMonthlyBookingReport,
	})

	go scheduler.Start()

	go func() {
		for {
			select {
			case err := <-scheduler.ErrChan:
				if err != nil {
					log.Println("Error:", err)
				}
			case msg := <-scheduler.SuccessChan:
				log.Print(msg)
			}
		}
	}()

	// Capture termination signals for graceful shutdown
	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)

	// Wait for termination signal
	<-sigChan
	log.Println("Received termination signal, shutting down...")

	// Stop the task manager and close channels
	scheduler.Stop()
	log.Println("All tasks stopped, exiting.")
}
