package main

import (
	"testing"
	"time"
)

func TestClassifyCompletion_CompletedAfterDue_ReturnsOverdue(t *testing.T) {
	due := time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC)
	completed := time.Date(2025, 6, 5, 14, 0, 0, 0, time.UTC)
	got := classifyCompletion(completed, due, 7)
	if got != "overdue_tasks" {
		t.Errorf("got %q, want overdue_tasks", got)
	}
}

func TestClassifyCompletion_CompletedOnDueDate_ReturnsDueSoon(t *testing.T) {
	due := time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC)
	completed := time.Date(2025, 6, 1, 10, 0, 0, 0, time.UTC)
	got := classifyCompletion(completed, due, 7)
	if got != "due_soon_tasks" {
		t.Errorf("got %q, want due_soon_tasks", got)
	}
}

func TestClassifyCompletion_CompletedWithinThreshold_ReturnsDueSoon(t *testing.T) {
	due := time.Date(2025, 6, 10, 0, 0, 0, 0, time.UTC)
	completed := time.Date(2025, 6, 5, 0, 0, 0, 0, time.UTC) // 5 days before due, threshold 7
	got := classifyCompletion(completed, due, 7)
	if got != "due_soon_tasks" {
		t.Errorf("got %q, want due_soon_tasks", got)
	}
}

func TestClassifyCompletion_CompletedAtExactThreshold_ReturnsDueSoon(t *testing.T) {
	due := time.Date(2025, 6, 10, 0, 0, 0, 0, time.UTC)
	completed := time.Date(2025, 6, 3, 0, 0, 0, 0, time.UTC) // exactly 7 days before due
	got := classifyCompletion(completed, due, 7)
	if got != "due_soon_tasks" {
		t.Errorf("got %q, want due_soon_tasks", got)
	}
}

func TestClassifyCompletion_CompletedBeyondThreshold_ReturnsUpcoming(t *testing.T) {
	due := time.Date(2025, 6, 30, 0, 0, 0, 0, time.UTC)
	completed := time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC) // 29 days before due, threshold 7
	got := classifyCompletion(completed, due, 7)
	if got != "upcoming_tasks" {
		t.Errorf("got %q, want upcoming_tasks", got)
	}
}

func TestClassifyCompletion_TimeNormalization_SameDayDifferentTimes(t *testing.T) {
	due := time.Date(2025, 6, 1, 23, 59, 59, 0, time.UTC)
	completed := time.Date(2025, 6, 1, 0, 0, 1, 0, time.UTC) // same day, different times
	got := classifyCompletion(completed, due, 7)
	// Same day → daysBefore == 0 → within threshold → due_soon
	if got != "due_soon_tasks" {
		t.Errorf("got %q, want due_soon_tasks", got)
	}
}
