package de.krisenvorrat.app.domain.usecase

import org.junit.Assert.assertEquals
import org.junit.Test

class CalculateTotalValueUseCaseTest {

    private val useCase = CalculateTotalValueUseCase()

    @Test
    fun test_invoke_withMultipleItems_returnsSumOfQuantityTimesPrice() {
        // Given
        val items = listOf(
            buildTestItem(id = "1", quantity = 3.0, unitPrice = 2.50),
            buildTestItem(id = "2", quantity = 1.0, unitPrice = 4.00),
            buildTestItem(id = "3", quantity = 5.0, unitPrice = 1.20)
        )

        // When
        val result = useCase(items)

        // Then
        assertEquals(17.50, result, 0.001)
    }

    @Test
    fun test_invoke_withEmptyList_returnsZero() {
        // Given
        val items = emptyList<Nothing>()

        // When
        val result = useCase(items)

        // Then
        assertEquals(0.0, result, 0.001)
    }

    @Test
    fun test_invoke_withZeroPrice_returnsZero() {
        // Given
        val items = listOf(
            buildTestItem(id = "1", quantity = 10.0, unitPrice = 0.0)
        )

        // When
        val result = useCase(items)

        // Then
        assertEquals(0.0, result, 0.001)
    }

    @Test
    fun test_invoke_withZeroQuantity_returnsZero() {
        // Given
        val items = listOf(
            buildTestItem(id = "1", quantity = 0.0, unitPrice = 5.0)
        )

        // When
        val result = useCase(items)

        // Then
        assertEquals(0.0, result, 0.001)
    }

    @Test
    fun test_invoke_withSingleItem_returnsCorrectValue() {
        // Given
        val items = listOf(
            buildTestItem(id = "1", quantity = 2.5, unitPrice = 3.00)
        )

        // When
        val result = useCase(items)

        // Then
        assertEquals(7.50, result, 0.001)
    }
}
