package adjustments

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

	commonSvc "gitlab.com/mbugroup/lti-api.git/internal/common/service"
	rAdjustmentStock "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/adjustments/repositories"
	sAdjustment "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/adjustments/services"
	rProductWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
	rproduct "gitlab.com/mbugroup/lti-api.git/internal/modules/master/products/repositories"
	rWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/repositories"
	rProjectFlockKandang "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/repositories"
	rStockLogs "gitlab.com/mbugroup/lti-api.git/internal/modules/shared/repositories"
	rUser "gitlab.com/mbugroup/lti-api.git/internal/modules/users/repositories"
	sUser "gitlab.com/mbugroup/lti-api.git/internal/modules/users/services"
	"gitlab.com/mbugroup/lti-api.git/internal/utils"
)

type AdjustmentModule struct{}

func (AdjustmentModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate *validator.Validate) {
	// Repositories
	stockLogsRepo := rStockLogs.NewStockLogRepository(db)
	warehouseRepo := rWarehouse.NewWarehouseRepository(db)
	productWarehouseRepo := rProductWarehouse.NewProductWarehouseRepository(db)
	projectFlockKandangRepo := rProjectFlockKandang.NewProjectFlockKandangRepository(db)
	projectFlockPopulationRepo := rProjectFlockKandang.NewProjectFlockPopulationRepository(db)
	userRepo := rUser.NewUserRepository(db)
	productRepo := rproduct.NewProductRepository(db)
	adjustmentStockRepo := rAdjustmentStock.NewAdjustmentStockRepository(db)
	fifoStockV2Service := commonSvc.NewFifoStockV2Service(db, utils.Log)

	adjustmentService := sAdjustment.NewAdjustmentService(
		productRepo,
		stockLogsRepo,
		warehouseRepo,
		productWarehouseRepo,
		adjustmentStockRepo,
		fifoStockV2Service,
		validate,
		projectFlockKandangRepo,
		projectFlockPopulationRepo,
	)
	userService := sUser.NewUserService(userRepo, validate)

	AdjustmentRoutes(router, userService, adjustmentService)
}
