package injections

import (
	"fmt"

	"github.com/go-playground/validator/v10"
	"github.com/gofiber/fiber/v2"
	commonRepo "gitlab.com/mbugroup/lti-api.git/internal/common/repository"
	commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
	"gitlab.com/mbugroup/lti-api.git/internal/utils"
	"gorm.io/gorm"

	rInjection "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/injections/repositories"
	sInjection "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/injections/services"

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

type InjectionModule struct{}

func (InjectionModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate *validator.Validate) {
	injectionRepo := rInjection.NewInjectionRepository(db)
	userRepo := rUser.NewUserRepository(db)

	approvalRepo := commonRepo.NewApprovalRepository(db)
	approvalService := commonSvc.NewApprovalService(approvalRepo)
	if err := approvalService.RegisterWorkflowSteps(utils.ApprovalWorkflowInjection, utils.InjectionApprovalSteps); err != nil {
		panic(fmt.Sprintf("failed to register injection approval workflow: %v", err))
	}

	injectionService := sInjection.NewInjectionService(injectionRepo, approvalService, validate)
	userService := sUser.NewUserService(userRepo, validate)

	InjectionRoutes(router, userService, injectionService)
}
