package activity_test

import (
	"context"
	"testing"

	"hyapp/pkg/xerr"
	activitydomain "hyapp/services/activity-service/internal/domain/activity"
	activityservice "hyapp/services/activity-service/internal/service/activity"
	"hyapp/services/activity-service/internal/testutil/mysqltest"
)

// TestGetActivityStatusUsesRepository 验证活动状态读取不依赖 gRPC transport。
func TestGetActivityStatusUsesRepository(t *testing.T) {
	repository := mysqltest.NewRepository(t)
	repository.PutActivity(activitydomain.Activity{ActivityID: "lucky-gift", Status: activitydomain.StatusActive})
	svc := activityservice.New(activityservice.Config{NodeID: "activity-a"}, repository)

	activity, err := svc.GetActivityStatus(context.Background(), "lucky-gift")
	if err != nil {
		t.Fatalf("GetActivityStatus failed: %v", err)
	}

	if activity.Status != activitydomain.StatusActive {
		t.Fatalf("unexpected activity: %+v", activity)
	}
}

// TestGetActivityStatusValidatesID 锁定空 activity_id 的错误 reason。
func TestGetActivityStatusValidatesID(t *testing.T) {
	svc := activityservice.New(activityservice.Config{NodeID: "activity-a"}, nil)

	_, err := svc.GetActivityStatus(context.Background(), "")
	if !xerr.IsCode(err, xerr.InvalidArgument) {
		t.Fatalf("expected INVALID_ARGUMENT, got %v", err)
	}
}
