package de.krisenvorrat.app.data.db

import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertThrows
import org.junit.Test
import java.time.LocalDate
import java.time.format.DateTimeParseException

class LocalDateConverterTest {

    private val converter = LocalDateConverter()

    @Test
    fun test_fromLocalDate_withDate_returnsIsoString() {
        // Given
        val date = LocalDate.of(2025, 12, 31)

        // When
        val result = converter.fromLocalDate(date)

        // Then
        assertEquals("2025-12-31", result)
    }

    @Test
    fun test_fromLocalDate_withNull_returnsNull() {
        // Given
        val date: LocalDate? = null

        // When
        val result = converter.fromLocalDate(date)

        // Then
        assertNull(result)
    }

    @Test
    fun test_toLocalDate_withIsoString_returnsDate() {
        // Given
        val isoString = "2025-12-31"

        // When
        val result = converter.toLocalDate(isoString)

        // Then
        assertEquals(LocalDate.of(2025, 12, 31), result)
    }

    @Test
    fun test_toLocalDate_withNull_returnsNull() {
        // Given
        val isoString: String? = null

        // When
        val result = converter.toLocalDate(isoString)

        // Then
        assertNull(result)
    }

    @Test
    fun test_toLocalDate_withInvalidString_throwsDateTimeParseException() {
        // Given
        val invalidString = "not-a-date"

        // When / Then
        assertThrows(DateTimeParseException::class.java) {
            converter.toLocalDate(invalidString)
        }
    }
}
