package de.trainingstagebuch.app.utils

import de.trainingstagebuch.app.repository.TrainingDayStatsItem
import org.junit.Assert.assertEquals
import org.junit.Test
import java.time.LocalDate

class TrainingStatsMetricsTest {

    @Test
    fun `averageParticipation returns period average for current month`() {
        val now = LocalDate.of(2026, 3, 20)
        val days = listOf(
            TrainingDayStatsItem(id = "1", date = "2026-03-01", participantCount = 10),
            TrainingDayStatsItem(id = "2", date = "2026-03-08", participantCount = 20),
            TrainingDayStatsItem(id = "3", date = "2026-02-20", participantCount = 30)
        )

        val result = TrainingStatsMetrics.averageParticipation(
            days = days,
            period = TrainingStatsMetrics.Period.CurrentMonth,
            now = now
        )

        assertEquals(15.0, result, 0.001)
    }

    @Test
    fun `averageParticipation quarter uses best quarter by training count`() {
        val now = LocalDate.of(2026, 3, 20)
        val days = listOf(
            TrainingDayStatsItem(id = "1", date = "2025-01-01", participantCount = 10),
            TrainingDayStatsItem(id = "2", date = "2025-01-05", participantCount = 20),
            TrainingDayStatsItem(id = "3", date = "2025-04-05", participantCount = 30)
        )

        val result = TrainingStatsMetrics.averageParticipation(
            days = days,
            period = TrainingStatsMetrics.Period.QuarterWithMostTrainings,
            now = now
        )

        assertEquals(15.0, result, 0.001)
    }
}
