package grpc

import (
	"context"

	walletv1 "hyapp.local/api/proto/wallet/v1"
	"hyapp/pkg/appcode"
	"hyapp/pkg/xerr"
	"hyapp/services/wallet-service/internal/domain/ledger"
)

// GetHostRevenueStats 返回主播周期钻石收益、POINT 兑换和去重送礼用户。
func (s *Server) GetHostRevenueStats(ctx context.Context, req *walletv1.GetHostRevenueStatsRequest) (*walletv1.GetHostRevenueStatsResponse, error) {
	ctx = appcode.WithContext(ctx, req.GetAppCode())
	stats, err := s.svc.GetHostRevenueStats(ctx, req.GetAppCode(), ledger.HostRevenueStatsQuery{
		HostUserID: req.GetHostUserId(),
		RegionID:   req.GetRegionId(),
		StartAtMS:  req.GetStartAtMs(),
		EndAtMS:    req.GetEndAtMs(),
	})
	if err != nil {
		return nil, xerr.ToGRPCError(err)
	}
	return &walletv1.GetHostRevenueStatsResponse{Stats: &walletv1.HostRevenueStats{
		DiamondEarnings:       stats.DiamondEarnings,
		DiamondExchanged:      stats.DiamondExchanged,
		PointDiamondEarnings:  stats.PointDiamondEarnings,
		PointDiamondExchanged: stats.PointDiamondExchanged,
		GiftSenders:           stats.GiftSenders,
	}}, nil
}
