package app.closer.data.remote

import java.time.Clock
import java.time.Instant
import java.time.ZoneId
import org.junit.Assert.assertEquals
import org.junit.Test

class FirestoreAnswerDataSourceTest {

    @Test
    fun `today local date string uses the clock timezone`() {
        val instant = Instant.parse("2026-06-20T02:30:00Z")

        val chicagoClock = Clock.fixed(instant, ZoneId.of("America/Chicago"))
        val tokyoClock = Clock.fixed(instant, ZoneId.of("Asia/Tokyo"))

        assertEquals("2026-06-19", FirestoreAnswerDataSource.todayLocalDateString(chicagoClock))
        assertEquals("2026-06-20", FirestoreAnswerDataSource.todayLocalDateString(tokyoClock))
    }

    @Test
    fun `local date string converts a UTC instant into the requested local zone`() {
        val instant = Instant.parse("2026-01-01T00:30:00Z")

        assertEquals(
            "2025-12-31",
            FirestoreAnswerDataSource.localDateString(instant, ZoneId.of("America/Los_Angeles"))
        )
        assertEquals(
            "2026-01-01",
            FirestoreAnswerDataSource.localDateString(instant, ZoneId.of("Europe/London"))
        )
    }
}
