package app

import (
	"google.golang.org/grpc"
	activityv1 "hyapp.local/api/proto/activity/v1"
	grpcserver "hyapp/services/activity-service/internal/transport/grpc"
)

func registerGRPCServers(server *grpc.Server, services *serviceBundle) {
	activityv1.RegisterActivityServiceServer(server, grpcserver.NewServer(services.activity))
	activityv1.RegisterMessageInboxServiceServer(server, grpcserver.NewMessageServer(services.message))
	// cron 入口只做调度适配；具体状态机仍在各 activity service 内部。
	// weekly-star 和 room-turnover 都依赖 wallet 发奖，所以这里必须把同一批已装配的 service 注入 cron server。
	activityv1.RegisterActivityCronServiceServer(server, grpcserver.NewCronServer(services.message, services.growth, services.achievement, services.weeklyStar, services.roomTurnoverReward))
	activityv1.RegisterTaskServiceServer(server, grpcserver.NewTaskServer(services.task))
	activityv1.RegisterAdminTaskServiceServer(server, grpcserver.NewAdminTaskServer(services.task))
	activityv1.RegisterGrowthLevelServiceServer(server, grpcserver.NewGrowthLevelServer(services.growth))
	activityv1.RegisterAdminGrowthLevelServiceServer(server, grpcserver.NewAdminGrowthLevelServer(services.growth))
	activityv1.RegisterAchievementServiceServer(server, grpcserver.NewAchievementServer(services.achievement))
	activityv1.RegisterAdminAchievementServiceServer(server, grpcserver.NewAdminAchievementServer(services.achievement))
	activityv1.RegisterLuckyGiftServiceServer(server, grpcserver.NewLuckyGiftServer(services.luckyGift))
	activityv1.RegisterAdminLuckyGiftServiceServer(server, grpcserver.NewAdminLuckyGiftServer(services.luckyGift))
	activityv1.RegisterRegistrationRewardServiceServer(server, grpcserver.NewRegistrationRewardServer(services.registrationReward))
	activityv1.RegisterAdminRegistrationRewardServiceServer(server, grpcserver.NewAdminRegistrationRewardServer(services.registrationReward))
	activityv1.RegisterSevenDayCheckInServiceServer(server, grpcserver.NewSevenDayCheckInServer(services.sevenDayCheckIn))
	activityv1.RegisterAdminSevenDayCheckInServiceServer(server, grpcserver.NewAdminSevenDayCheckInServer(services.sevenDayCheckIn))
	activityv1.RegisterWeeklyStarServiceServer(server, grpcserver.NewWeeklyStarServer(services.weeklyStar))
	activityv1.RegisterAdminWeeklyStarServiceServer(server, grpcserver.NewAdminWeeklyStarServer(services.weeklyStar))
	activityv1.RegisterRoomTurnoverRewardServiceServer(server, grpcserver.NewRoomTurnoverRewardServer(services.roomTurnoverReward))
	activityv1.RegisterAdminRoomTurnoverRewardServiceServer(server, grpcserver.NewAdminRoomTurnoverRewardServer(services.roomTurnoverReward))
	// BroadcastServer 同时承载 BroadcastService 和 RoomEventConsumerService。
	// gRPC 直连投递和 MQ 消费都必须经过相同的 room event fanout 顺序，否则本地验证会通过但线上 MQ 路径漏积分。
	broadcastServer := grpcserver.NewBroadcastServer(services.broadcast, services.growth, services.weeklyStar, services.roomTurnoverReward)
	activityv1.RegisterBroadcastServiceServer(server, broadcastServer)
	activityv1.RegisterRoomEventConsumerServiceServer(server, broadcastServer)
	activityv1.RegisterFirstRechargeRewardServiceServer(server, grpcserver.NewFirstRechargeRewardServer(services.firstRechargeReward))
	activityv1.RegisterAdminFirstRechargeRewardServiceServer(server, grpcserver.NewAdminFirstRechargeRewardServer(services.firstRechargeReward))
	activityv1.RegisterCumulativeRechargeRewardServiceServer(server, grpcserver.NewCumulativeRechargeRewardServer(services.cumulativeRecharge))
	activityv1.RegisterAdminCumulativeRechargeRewardServiceServer(server, grpcserver.NewAdminCumulativeRechargeRewardServer(services.cumulativeRecharge))
}
