package closings

import (
	"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"
	rClosing "gitlab.com/mbugroup/lti-api.git/internal/modules/closings/repositories"
	sClosing "gitlab.com/mbugroup/lti-api.git/internal/modules/closings/services"
	rExpenseRealization "gitlab.com/mbugroup/lti-api.git/internal/modules/expenses/repositories"
	rMarketings "gitlab.com/mbugroup/lti-api.git/internal/modules/marketing/repositories"
	rProductionStandard "gitlab.com/mbugroup/lti-api.git/internal/modules/master/production-standards/repositories"
	rChickin "gitlab.com/mbugroup/lti-api.git/internal/modules/production/chickins/repositories"
	rProjectFlock "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
	rRecording "gitlab.com/mbugroup/lti-api.git/internal/modules/production/recordings/repositories"
	rPurchase "gitlab.com/mbugroup/lti-api.git/internal/modules/purchases/repositories"

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

type ClosingModule struct{}

func (ClosingModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate *validator.Validate) {
	closingRepo := rClosing.NewClosingRepository(db)
	userRepo := rUser.NewUserRepository(db)
	projectFlockRepo := rProjectFlock.NewProjectflockRepository(db)
	projectFlockKandangRepo := rProjectFlock.NewProjectFlockKandangRepository(db)
	projectBudgetRepo := rProjectFlock.NewProjectBudgetRepository(db)
	marketingRepo := rMarketings.NewMarketingRepository(db)
	marketingDeliveryProductRepo := rMarketings.NewMarketingDeliveryProductRepository(db)
	expenseRealizationRepo := rExpenseRealization.NewExpenseRealizationRepository(db)
	chickinRepo := rChickin.NewChickinRepository(db)
	recordingRepo := rRecording.NewRecordingRepository(db)
	standardGrowthDetailRepo := rProductionStandard.NewStandardGrowthDetailRepository(db)
	productionStandardDetailRepo := rProductionStandard.NewProductionStandardDetailRepository(db)
	purchaseRepo := rPurchase.NewPurchaseRepository(db)
	approvalRepo := commonRepo.NewApprovalRepository(db)
	approvalService := commonSvc.NewApprovalService(approvalRepo)
	hppCostRepo := commonRepo.NewHppCostRepository(db)
	hppService := commonSvc.NewHppService(hppCostRepo)

	closingService := sClosing.NewClosingService(closingRepo, projectFlockRepo, projectFlockKandangRepo, marketingRepo, marketingDeliveryProductRepo, approvalService, expenseRealizationRepo, projectBudgetRepo, chickinRepo, purchaseRepo, recordingRepo, standardGrowthDetailRepo, productionStandardDetailRepo, validate)
	closingKeuanganService := sClosing.NewClosingKeuanganService(projectFlockRepo, projectFlockKandangRepo, marketingDeliveryProductRepo, expenseRealizationRepo, projectBudgetRepo, chickinRepo, recordingRepo, hppService, hppCostRepo)
	sapronakService := sClosing.NewSapronakService(closingRepo, projectFlockKandangRepo, validate)
	userService := sUser.NewUserService(userRepo, validate)

	ClosingRoutes(router, userService, closingService, sapronakService, closingKeuanganService)
}
