package main

import (
	"context"
	"os"
	"os/signal"

	"git.optclblast.xyz/draincloud/draincloud-core/internal/app"
	filesengine "git.optclblast.xyz/draincloud/draincloud-core/internal/files_engine"
	"git.optclblast.xyz/draincloud/draincloud-core/internal/plugin"
	"git.optclblast.xyz/draincloud/draincloud-core/internal/storage/postgres"
)

func main() {
	ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
	defer cancel()

	plugin.MustNewPluginLoader(ctx, 8081, plugin.NewPluginStore()).
		Run(ctx)

	pg := postgres.New(ctx, "postgres://draincloud:mysuperstrongpassword@127.0.0.1:5432/draincloud?sslmode=disable")

	// TODO move cron on a separate job (k8s cronjob / docker cron)
	// cleanupSessionsCron := cleanupsessions.New(pg)
	// cleanupSessionsCron.Run(ctx)

	engine := filesengine.NewFilesEngine(nil, nil)

	go app.New(ctx, pg, engine).
		Run(ctx)

	<-ctx.Done()
}
