package dailyChecklists

import (
	"context"
	"fmt"

	"github.com/go-playground/validator/v10"
	"github.com/gofiber/fiber/v2"
	"gorm.io/gorm"

	commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
	commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
	rDailyChecklist "gitlab.com/mbugroup/lti-api.git/internal/modules/daily-checklists/repositories"
	sDailyChecklist "gitlab.com/mbugroup/lti-api.git/internal/modules/daily-checklists/services"
	rPhases "gitlab.com/mbugroup/lti-api.git/internal/modules/master/phasess/repositories"

	rUser "gitlab.com/mbugroup/lti-api.git/internal/modules/users/repositories"
	sUser "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services"
)

type DailyChecklistModule struct{}

func (DailyChecklistModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate *validator.Validate) {
	dailyChecklistRepo := rDailyChecklist.NewDailyChecklistRepository(db)
	phasesRepo := rPhases.NewPhasesRepository(db)
	userRepo := rUser.NewUserRepository(db)
	documentRepo := commonRepo.NewDocumentRepository(db)
	documentSvc, err := commonSvc.NewDocumentServiceFromConfig(context.Background(), documentRepo)
	if err != nil {
		panic(fmt.Sprintf("failed to create document service: %v", err))
	}

	dailyChecklistService := sDailyChecklist.NewDailyChecklistService(dailyChecklistRepo, phasesRepo, validate, documentSvc)
	userService := sUser.NewUserService(userRepo, validate)

	DailyChecklistRoutes(router, userService, dailyChecklistService)
}
