package router

import (
	"github.com/movscript/movscript/internal/interfaces/http/handler"
	wsiface "github.com/movscript/movscript/internal/interfaces/ws"
)

type handlers struct {
	projects          *handler.ProjectHandler
	decisions         *handler.DecisionHandler
	users             *handler.UserHandler
	userAdmin         *handler.UserAdminHandler
	auth              *handler.AuthHandler
	ai                *handler.AIHandler
	resources         *handler.ResourceHandler
	externalResources *handler.ExternalResourceHandler
	shotReferences    *handler.ShotReferenceHandler
	resourceFolders   *handler.ResourceFolderHandler
	resourceAdmin     *handler.ResourceAdminHandler
	canvases          *handler.CanvasHandler
	models            *handler.ModelsHandler
	jobs              *handler.JobHandler
	modelGateway      *handler.ModelGatewayHandler
	debug             *handler.DebugHandler
	plugin            *handler.PluginHandler
	hub               *handler.HubHandler
	registry          *handler.RegistryHandler
	audit             *handler.AuditHandler
	usageAdmin        *handler.UsageAdminHandler
	cloudFileConfig   *handler.CloudFileConfigHandler
	adminSettings     *handler.AdminSettingsHandler
	entitlement       *handler.EntitlementHandler
	org               *handler.OrgHandler
	orgAdmin          *handler.OrgAdminHandler
	adminOverview     *handler.AdminOverviewHandler
	agentTelemetry    *handler.AgentTelemetryHandler
	ws                *wsiface.Handler
}

func newHandlers(deps Dependencies) handlers {
	db := deps.DB
	cfg := deps.Config
	store := deps.Store
	tokens := deps.Tokens
	registry := deps.Registry
	aiService := deps.AIService
	cacheStore := deps.Cache
	imageVerifier := deps.ImageVerifier

	return handlers{
		projects:          handler.NewProjectHandlerWithConfigAndEncryption(db, cfg, deps.EncryptionKey, cacheStore),
		decisions:         handler.NewDecisionHandler(db),
		users:             handler.NewUserHandler(db),
		userAdmin:         handler.NewUserAdminHandler(db),
		auth:              handler.NewAuthHandlerWithConfigAndEncryption(db, tokens, cfg, deps.EncryptionKey),
		ai:                handler.NewAIHandler(db, cfg.EncryptionKey, registry),
		resources:         handler.NewResourceHandler(db, store, imageVerifier, cfg.MaxUploadBytes, cacheStore),
		externalResources: handler.NewExternalResourceHandler(db, cfg.EncryptionKey),
		shotReferences:    handler.NewShotReferenceHandler(db, store, imageVerifier, cfg.MaxUploadBytes, cacheStore),
		resourceFolders:   handler.NewResourceFolderHandler(db, cacheStore),
		resourceAdmin:     handler.NewResourceAdminHandler(db, store),
		canvases:          handler.NewCanvasHandler(db, registry, aiService, store),
		models:            handler.NewModelsHandler(aiService, cacheStore),
		jobs:              handler.NewJobHandler(db, aiService),
		modelGateway:      handler.NewModelGatewayHandler(db, aiService),
		debug:             handler.NewDebugHandler(db, deps.EncryptionKey),
		plugin:            handler.NewPluginHandler(db),
		hub:               handler.NewHubHandler(db, store, cfg.HubAdminToken),
		registry:          handler.NewRegistryHandler(),
		audit:             handler.NewAuditHandler(db),
		usageAdmin:        handler.NewUsageAdminHandler(db),
		cloudFileConfig:   handler.NewCloudFileConfigHandler(db, cfg.EncryptionKey),
		adminSettings:     handler.NewAdminSettingsHandler(db, cfg.EncryptionKey),
		entitlement:       handler.NewEntitlementHandler(deps.Entitlements),
		org:               handler.NewOrgHandler(db, tokens),
		orgAdmin:          handler.NewOrgAdminHandler(db),
		adminOverview:     handler.NewAdminOverviewHandler(db),
		agentTelemetry:    handler.NewAgentTelemetryHandler(nil),
		ws:                wsiface.NewHandler(),
	}
}
