package commerce

import (
	"testing"
	"time"
)

func TestActivityStatus(t *testing.T) {
	now := time.Date(2026, time.July, 11, 12, 0, 0, 0, time.UTC)
	past := now.Add(-time.Hour)
	future := now.Add(time.Hour)

	tests := []struct {
		name string
		item Activity
		want string
	}{
		{name: "draft", item: Activity{IsPublished: false, LimitedTime: true, StartsAt: &past, EndsAt: &future}, want: "draft"},
		{name: "long term", item: Activity{IsPublished: true, LimitedTime: false}, want: "ongoing"},
		{name: "upcoming", item: Activity{IsPublished: true, LimitedTime: true, StartsAt: &future, EndsAt: timePointer(future.Add(time.Hour))}, want: "upcoming"},
		{name: "ongoing", item: Activity{IsPublished: true, LimitedTime: true, StartsAt: &past, EndsAt: &future}, want: "ongoing"},
		{name: "ended", item: Activity{IsPublished: true, LimitedTime: true, StartsAt: timePointer(past.Add(-time.Hour)), EndsAt: &past}, want: "ended"},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, _ := activityStatus(tt.item, now)
			if got != tt.want {
				t.Fatalf("status = %q, want %q", got, tt.want)
			}
		})
	}
}

func TestValidateActivityTiming(t *testing.T) {
	now := time.Now().UTC()
	item := Activity{Title: "活动", Description: "描述", LimitedTime: true, StartsAt: &now, EndsAt: &now}
	if err := validateActivity(item); err == nil {
		t.Fatal("expected invalid timing error")
	}
}

func timePointer(value time.Time) *time.Time {
	return &value
}
