package initials

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"

	rInitial "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/initials/repositories"
	sInitial "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/initials/services"

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

type InitialModule struct{}

func (InitialModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate *validator.Validate) {
	initialRepo := rInitial.NewInitialRepository(db)
	userRepo := rUser.NewUserRepository(db)

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

	initialService := sInitial.NewInitialService(initialRepo, approvalService, validate)
	userService := sUser.NewUserService(userRepo, validate)

	InitialRoutes(router, userService, initialService)
}
