package main

import (
	"log"

	"github.com/Vomitblood/cspj-application/server/internal/cli"
	"github.com/Vomitblood/cspj-application/server/internal/config"
	"github.com/Vomitblood/cspj-application/server/internal/db"
	"github.com/Vomitblood/cspj-application/server/internal/http_server"
	"github.com/Vomitblood/cspj-application/server/internal/log_watcher"
	"github.com/Vomitblood/cspj-application/server/internal/telegram"
	"github.com/Vomitblood/cspj-application/server/internal/webdav"
)

func main() {
	cli.GetFlags()
	log.Printf("Log directory set to: %s", config.LogDirectory)

	var err error
	db.DbPool, err = db.ConnectToDb()
	if err != nil {
		log.Fatalf("Failed to connect to db: %v", err)
	}
	defer db.DbPool.Close()

	// init webdav webdavClient
	webdavClient := webdav.Init()

	// init telegram bot
	tgBot := telegram.Init(webdavClient)

	// start log watcher
	go log_watcher.WatchFile(tgBot)

	http_server.ServeApi()
}
