package payments

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"
	"gorm.io/gorm"

	rPayment "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/payments/repositories"
	sPayment "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/payments/services"
	utils "gitlab.com/mbugroup/lti-api.git/internal/utils"

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

type PaymentModule struct{}

func (PaymentModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate *validator.Validate) {
	paymentRepo := rPayment.NewPaymentRepository(db)
	userRepo := rUser.NewUserRepository(db)

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

	paymentService := sPayment.NewPaymentService(paymentRepo, approvalService, validate)
	userService := sUser.NewUserService(userRepo, validate)

	PaymentRoutes(router, userService, paymentService)
}
