package activityclient

import (
	"context"

	activityv1 "hyapp.local/api/proto/activity/v1"

	"google.golang.org/grpc"
)

// Client 是 admin-server 访问 activity-service 任务配置能力的最小 gRPC 依赖。
type Client interface {
	ListTaskDefinitions(ctx context.Context, req *activityv1.ListTaskDefinitionsRequest) (*activityv1.ListTaskDefinitionsResponse, error)
	UpsertTaskDefinition(ctx context.Context, req *activityv1.UpsertTaskDefinitionRequest) (*activityv1.UpsertTaskDefinitionResponse, error)
	SetTaskDefinitionStatus(ctx context.Context, req *activityv1.SetTaskDefinitionStatusRequest) (*activityv1.SetTaskDefinitionStatusResponse, error)
	GetRegistrationRewardConfig(ctx context.Context, req *activityv1.GetRegistrationRewardConfigRequest) (*activityv1.GetRegistrationRewardConfigResponse, error)
	UpdateRegistrationRewardConfig(ctx context.Context, req *activityv1.UpdateRegistrationRewardConfigRequest) (*activityv1.UpdateRegistrationRewardConfigResponse, error)
	ListRegistrationRewardClaims(ctx context.Context, req *activityv1.ListRegistrationRewardClaimsRequest) (*activityv1.ListRegistrationRewardClaimsResponse, error)
	RemoveRegionBroadcastMember(ctx context.Context, req *activityv1.RemoveRegionBroadcastMemberRequest) (*activityv1.RemoveRegionBroadcastMemberResponse, error)
}

type GRPCClient struct {
	taskClient               activityv1.AdminTaskServiceClient
	registrationRewardClient activityv1.AdminRegistrationRewardServiceClient
	broadcastClient          activityv1.BroadcastServiceClient
}

func NewGRPC(conn grpc.ClientConnInterface) *GRPCClient {
	return &GRPCClient{
		taskClient:               activityv1.NewAdminTaskServiceClient(conn),
		registrationRewardClient: activityv1.NewAdminRegistrationRewardServiceClient(conn),
		broadcastClient:          activityv1.NewBroadcastServiceClient(conn),
	}
}

func (c *GRPCClient) ListTaskDefinitions(ctx context.Context, req *activityv1.ListTaskDefinitionsRequest) (*activityv1.ListTaskDefinitionsResponse, error) {
	return c.taskClient.ListTaskDefinitions(ctx, req)
}

func (c *GRPCClient) UpsertTaskDefinition(ctx context.Context, req *activityv1.UpsertTaskDefinitionRequest) (*activityv1.UpsertTaskDefinitionResponse, error) {
	return c.taskClient.UpsertTaskDefinition(ctx, req)
}

func (c *GRPCClient) SetTaskDefinitionStatus(ctx context.Context, req *activityv1.SetTaskDefinitionStatusRequest) (*activityv1.SetTaskDefinitionStatusResponse, error) {
	return c.taskClient.SetTaskDefinitionStatus(ctx, req)
}

func (c *GRPCClient) GetRegistrationRewardConfig(ctx context.Context, req *activityv1.GetRegistrationRewardConfigRequest) (*activityv1.GetRegistrationRewardConfigResponse, error) {
	return c.registrationRewardClient.GetRegistrationRewardConfig(ctx, req)
}

func (c *GRPCClient) UpdateRegistrationRewardConfig(ctx context.Context, req *activityv1.UpdateRegistrationRewardConfigRequest) (*activityv1.UpdateRegistrationRewardConfigResponse, error) {
	return c.registrationRewardClient.UpdateRegistrationRewardConfig(ctx, req)
}

func (c *GRPCClient) ListRegistrationRewardClaims(ctx context.Context, req *activityv1.ListRegistrationRewardClaimsRequest) (*activityv1.ListRegistrationRewardClaimsResponse, error) {
	return c.registrationRewardClient.ListRegistrationRewardClaims(ctx, req)
}

func (c *GRPCClient) RemoveRegionBroadcastMember(ctx context.Context, req *activityv1.RemoveRegionBroadcastMemberRequest) (*activityv1.RemoveRegionBroadcastMemberResponse, error) {
	return c.broadcastClient.RemoveRegionBroadcastMember(ctx, req)
}
