package database

import (
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

func TestClassifyCompletion_CompletedAfterDue(t *testing.T) {
	dueDate := time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC)
	completedAt := time.Date(2025, 6, 5, 14, 30, 0, 0, time.UTC) // 4 days after due

	result := classifyCompletion(completedAt, dueDate, 30)

	assert.Equal(t, "overdue_tasks", result)
}

func TestClassifyCompletion_CompletedOnDueDate(t *testing.T) {
	dueDate := time.Date(2025, 6, 15, 0, 0, 0, 0, time.UTC)
	completedAt := time.Date(2025, 6, 15, 10, 0, 0, 0, time.UTC) // same day

	result := classifyCompletion(completedAt, dueDate, 30)

	// Completed on the due date: daysBefore == 0, which is <= threshold → due_soon_tasks
	assert.Equal(t, "due_soon_tasks", result)
}

func TestClassifyCompletion_CompletedWithinThreshold(t *testing.T) {
	dueDate := time.Date(2025, 7, 1, 0, 0, 0, 0, time.UTC)
	completedAt := time.Date(2025, 6, 10, 8, 0, 0, 0, time.UTC) // 21 days before due

	result := classifyCompletion(completedAt, dueDate, 30)

	// 21 days before due, within 30-day threshold → due_soon_tasks
	assert.Equal(t, "due_soon_tasks", result)
}

func TestClassifyCompletion_CompletedBeyondThreshold(t *testing.T) {
	dueDate := time.Date(2025, 9, 1, 0, 0, 0, 0, time.UTC)
	completedAt := time.Date(2025, 6, 1, 12, 0, 0, 0, time.UTC) // 92 days before due

	result := classifyCompletion(completedAt, dueDate, 30)

	// 92 days before due, beyond 30-day threshold → upcoming_tasks
	assert.Equal(t, "upcoming_tasks", result)
}
