// Package activityclient adapts activity-service registration reward RPCs for user-service.
package activityclient

import (
	"context"
	"time"

	"google.golang.org/grpc"
	activityv1 "hyapp.local/api/proto/activity/v1"
	authservice "hyapp/services/user-service/internal/service/auth"
)

type Client struct {
	client activityv1.RegistrationRewardServiceClient
}

func NewGRPC(conn grpc.ClientConnInterface) *Client {
	return &Client{client: activityv1.NewRegistrationRewardServiceClient(conn)}
}

// IssueRegistrationReward 只发起注册奖励幂等命令；可领取判断和实际发放都在 activity-service。
func (c *Client) IssueRegistrationReward(ctx context.Context, command authservice.RegistrationRewardCommand) error {
	if c == nil || c.client == nil {
		return nil
	}
	_, err := c.client.IssueRegistrationReward(ctx, &activityv1.IssueRegistrationRewardRequest{
		Meta: &activityv1.RequestMeta{
			RequestId: command.RequestID,
			Caller:    "user-service",
			AppCode:   command.AppCode,
			SentAtMs:  time.Now().UnixMilli(),
		},
		UserId:    command.UserID,
		CommandId: command.CommandID,
	})
	return err
}
