package project_flocks

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"

	rProductWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/repositories"
	rFlock "gitlab.com/mbugroup/lti-api.git/internal/modules/master/flocks/repositories"
	rKandang "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/repositories"
	rNonstock "gitlab.com/mbugroup/lti-api.git/internal/modules/master/nonstocks/repositories"
	rWarehouse "gitlab.com/mbugroup/lti-api.git/internal/modules/master/warehouses/repositories"
	rProjectBudget "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/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"
	rTransferLaying "gitlab.com/mbugroup/lti-api.git/internal/modules/production/transfer_layings/repositories"

	sProjectflock "gitlab.com/mbugroup/lti-api.git/internal/modules/production/project_flocks/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 ProjectflockModule struct{}

func (ProjectflockModule) RegisterRoutes(router fiber.Router, db *gorm.DB, validate *validator.Validate) {
	flockRepo := rFlock.NewFlockRepository(db)
	kandangRepo := rKandang.NewKandangRepository(db)
	nonstockRepo := rNonstock.NewNonstockRepository(db)
	projectflockRepo := rProjectflock.NewProjectflockRepository(db)
	projectflockKandangRepo := rProjectflock.NewProjectFlockKandangRepository(db)
	projectFlockPopulationRepo := rProjectflock.NewProjectFlockPopulationRepository(db)
	recordingRepo := rRecording.NewRecordingRepository(db)
	transferLayingRepo := rTransferLaying.NewTransferLayingRepository(db)
	warehouseRepo := rWarehouse.NewWarehouseRepository(db)
	productWarehouseRepo := rProductWarehouse.NewProductWarehouseRepository(db)
	projectBudgetRepo := rProjectBudget.NewProjectBudgetRepository(db)
	userRepo := rUser.NewUserRepository(db)

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

	projectflockService := sProjectflock.NewProjectflockService(projectflockRepo, flockRepo, kandangRepo, projectflockKandangRepo, warehouseRepo, productWarehouseRepo, projectBudgetRepo, nonstockRepo, projectFlockPopulationRepo, recordingRepo, transferLayingRepo, approvalService, validate)
	userService := sUser.NewUserService(userRepo, validate)

	ProjectflockRoutes(router, userService, projectflockService)
}
