package userleaderboard

import (
	"testing"
	"time"
)

func TestPeriodWindowUsesUTCBoundaries(t *testing.T) {
	now := time.Date(2026, 5, 20, 15, 30, 0, 0, time.FixedZone("CST", 8*60*60))

	todayStart, todayEnd := periodWindow(PeriodToday, now)
	if todayStart != time.Date(2026, 5, 20, 0, 0, 0, 0, time.UTC) {
		t.Fatalf("today start = %s", todayStart)
	}
	if !todayEnd.Equal(now.UTC()) {
		t.Fatalf("today end = %s", todayEnd)
	}

	weekStart, _ := periodWindow(PeriodWeek, now)
	if weekStart != time.Date(2026, 5, 18, 0, 0, 0, 0, time.UTC) {
		t.Fatalf("week start = %s", weekStart)
	}

	monthStart, _ := periodWindow(PeriodMonth, now)
	if monthStart != time.Date(2026, 5, 1, 0, 0, 0, 0, time.UTC) {
		t.Fatalf("month start = %s", monthStart)
	}
}

func TestNormalizeQueryDefaultsAndCapsPageSize(t *testing.T) {
	query := NormalizeQuery(Query{BoardType: "receiver", Period: "monthly", PageSize: 500})
	if query.BoardType != BoardTypeReceived || query.Period != PeriodMonth {
		t.Fatalf("query = %+v", query)
	}
	if query.Page != 1 || query.PageSize != maxPageSize {
		t.Fatalf("pagination = page %d pageSize %d", query.Page, query.PageSize)
	}
}
