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.RegisterAdminActivityTemplateServiceServer(server, grpcserver.NewAdminActivityTemplateServer(services.activityTemplate))
	activityv1.RegisterActivityTemplateRuntimeServiceServer(server, grpcserver.NewActivityTemplateRuntimeServer(services.activityTemplate))
	activityv1.RegisterMessageInboxServiceServer(server, grpcserver.NewMessageServer(services.message))
	activityv1.RegisterMessageActionConfirmServiceServer(server, grpcserver.NewActionConfirmServer(services.actionConfirm))
	// 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, services.agencyOpening, services.cpWeeklyRank, services.activityTemplate))
	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.RegisterWheelServiceServer(server, grpcserver.NewWheelServer(services.wheel))
	activityv1.RegisterAdminWheelServiceServer(server, grpcserver.NewAdminWheelServer(services.wheel))
	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))
	cpWeeklyRankServer := grpcserver.NewCPWeeklyRankServer(services.cpWeeklyRank)
	activityv1.RegisterCPWeeklyRankServiceServer(server, cpWeeklyRankServer)
	activityv1.RegisterAdminCPWeeklyRankServiceServer(server, cpWeeklyRankServer)
	activityv1.RegisterAgencyOpeningServiceServer(server, grpcserver.NewAgencyOpeningServer(services.agencyOpening))
	activityv1.RegisterAdminAgencyOpeningServiceServer(server, grpcserver.NewAdminAgencyOpeningServer(services.agencyOpening))
	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.task, services.roomTurnoverReward, services.agencyOpening, services.activityTemplate)
	activityv1.RegisterBroadcastServiceServer(server, broadcastServer)
	activityv1.RegisterRoomEventConsumerServiceServer(server, broadcastServer)
	activityv1.RegisterAdminBroadcastServiceServer(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))
	activityv1.RegisterInviteActivityRewardServiceServer(server, grpcserver.NewInviteActivityRewardServer(services.inviteActivityReward))
	activityv1.RegisterAdminInviteActivityRewardServiceServer(server, grpcserver.NewAdminInviteActivityRewardServer(services.inviteActivityReward))
}
