package main

import (
	"log"

	"senlinai-agent/backend/internal/config"
	"senlinai-agent/backend/internal/httpx"
	"senlinai-agent/backend/internal/logic/auth"
	"senlinai-agent/backend/internal/logic/files"
	"senlinai-agent/backend/internal/logic/inbox"
	"senlinai-agent/backend/internal/logic/projects"
	"senlinai-agent/backend/internal/models"
)

func main() {
	cfg := config.Load()

	err := models.New(cfg.DSN)
	if err != nil {
		log.Fatal(err)
	}

	authService := auth.NewService(cfg.AuthSecret)
	projectHandler := projects.NewHandler(projects.NewService(), files.NewService(cfg.StorageDir))
	inboxHandler := inbox.NewHandler(inbox.NewService(inbox.StaticAnalyzer{}))
	authHandler := auth.NewHandler(authService)
	appRouter := httpx.NewProtectedRouter(cfg, authService.VerifySession, authHandler, projectHandler, inboxHandler)
	if err := appRouter.Run(":" + cfg.Port); err != nil {
		log.Fatal(err)
	}
}
