package main

import (
	"actatempus_backend/internal/application/repository"
	"actatempus_backend/internal/application/services"
	"actatempus_backend/internal/infrastructure/config"
	"actatempus_backend/internal/infrastructure/data"
	"actatempus_backend/internal/interfaces/http"
	"fmt"
	"log"
)

func main() {
	// Lese die Konfiguration ein
	cfg, err := config.LoadConfig(".")
	if err != nil {
		log.Fatalf("could not load config: %v", err)
	}

	database, err := data.NewPrismaDatabase()

	if err != nil {
		log.Fatalf("could not initialize database: %v", err)
	}

	// Initialize repositories
	userRepo := repository.NewUserRepository(database.Users())
	projectRepo := repository.NewProjectRepository(database.Projects())
	projectTaskRepo := repository.NewProjectTaskRepository(database.ProjectTasks())
	timeEntryRepo := repository.NewTimeEntryRepository(database.TimeEntries())
	authRepo := repository.NewInMemoryAuthRepositoryImpl("secret")

	// Initialize services
	userService := services.NewUserService(authRepo, userRepo)
	projectService := services.NewProjectService(authRepo, projectRepo)
	projectTaskService := services.NewProjectTaskService(authRepo, projectTaskRepo)
	timeEntryService := services.NewTimeEntryService(authRepo, timeEntryRepo)
	authService := services.NewAuthService(authRepo, userRepo)

	// Initialize and start the server
	server := http.NewServer(cfg, userService, projectService, projectTaskService, timeEntryService, authService)

	fmt.Println("Starting ActaTempus server on port 8080...")
	if err := server.Start(); err != nil {
		log.Fatalf("server failed to start: %v", err)
	}
}
