package api

import (
	"boostai-backend/internal/aireview"
	"boostai-backend/internal/assignmentgen"
	"boostai-backend/internal/config"
	"boostai-backend/internal/database"
	adminhandler "boostai-backend/internal/handlers/api/admin"
	answershandler "boostai-backend/internal/handlers/api/answers"
	assignmentshandler "boostai-backend/internal/handlers/api/assignments"
	classroomshandler "boostai-backend/internal/handlers/api/classrooms"
	messageshandler "boostai-backend/internal/handlers/api/messages"
	questionshandler "boostai-backend/internal/handlers/api/questions"
	usershandler "boostai-backend/internal/handlers/api/users"
	"boostai-backend/internal/questiongen"
	"boostai-backend/internal/sqlc"
)

type Handler struct {
	users       *usershandler.Handler
	classrooms  *classroomshandler.Handler
	messages    *messageshandler.Handler
	questions   *questionshandler.Handler
	assignments *assignmentshandler.Handler
	answers     *answershandler.Handler
	admin       *adminhandler.Handler
}

func NewHandler(db *database.DB, cfg *config.Config) *Handler {
	queries := sqlc.New(db.Pool)
	aiReviewService := aireview.NewService(cfg.AIReviewEndpoint, cfg.AIReviewAPIKey, cfg.AIReviewModel)
	questionGenerator := questiongen.NewService()
	assignmentGenerator := assignmentgen.NewService(db, questionGenerator)

	return &Handler{
		users:       usershandler.NewHandler(queries),
		classrooms:  classroomshandler.NewHandler(queries),
		messages:    messageshandler.NewHandler(db),
		questions:   questionshandler.NewHandler(queries, questionGenerator),
		assignments: assignmentshandler.NewHandler(queries, aiReviewService, assignmentGenerator),
		answers:     answershandler.NewHandler(queries, aiReviewService),
		admin:       adminhandler.NewHandler(db, cfg),
	}
}
