package managerapi

import (
	"hyapp/services/gateway-service/internal/client"
	"hyapp/services/gateway-service/internal/transport/http/httproutes"
)

// Handler owns manager-center HTTP endpoints that are still part of the app gateway.
// Capability checks stay in user-service, and resource grants stay in wallet-service.
type Handler struct {
	walletClient        client.WalletClient
	userHostClient      client.UserHostClient
	userHostAdminClient client.UserHostAdminClient
	userProfileClient   client.UserProfileClient
	growthLevelClient   client.GrowthLevelClient
	// broadcastClient 只负责国家跨区域后的旧群清理；国家和房间迁移事实仍由 user-service outbox 驱动。
	broadcastClient client.BroadcastClient
	// dashboardCache 缓存经理团队工资统计，避免每次进入经理中心都做组织树 + 周期账户双聚合。
	dashboardCache managerDashboardCache
}

type Config struct {
	WalletClient        client.WalletClient
	UserHostClient      client.UserHostClient
	UserHostAdminClient client.UserHostAdminClient
	UserProfileClient   client.UserProfileClient
	GrowthLevelClient   client.GrowthLevelClient
	BroadcastClient     client.BroadcastClient
}

func New(config Config) *Handler {
	return &Handler{
		walletClient:        config.WalletClient,
		userHostClient:      config.UserHostClient,
		userHostAdminClient: config.UserHostAdminClient,
		userProfileClient:   config.UserProfileClient,
		growthLevelClient:   config.GrowthLevelClient,
		broadcastClient:     config.BroadcastClient,
	}
}

func (h *Handler) ManagerHandlers() httproutes.ManagerHandlers {
	return httproutes.ManagerHandlers{
		ListManagerGrantResources:  h.listManagerGrantResources,
		GrantManagerResource:       h.grantManagerResource,
		LookupBusinessUsers:        h.lookupBusinessUsers,
		GetManagerOverview:         h.getManagerOverview,
		SearchManagerUsers:         h.searchManagerUsers,
		GrantManagerVIP:            h.grantManagerVIP,
		ManagerBlocks:              h.managerBlocks,
		ListManagerBlocks:          h.listManagerBlocks,
		CreateManagerBlock:         h.createManagerBlock,
		UnblockManagerBlock:        h.unblockManagerBlock,
		SetManagerUserLevel:        h.setManagerUserLevel,
		CreateManagerBDLeader:      h.createManagerBDLeader,
		TransferManagerUserCountry: h.transferManagerUserCountry,
	}
}
