package dev.privacyllc.period.core.export

import dev.privacyllc.period.domain.cycle.PeriodRecord
import dev.privacyllc.period.domain.cycle.PeriodRecordSource
import dev.privacyllc.period.domain.cycle.SpottingRecord
import java.time.LocalDate
import java.time.LocalTime

/**
 * One fixture, shared by every test that renders.
 *
 * Deliberately covers the shapes that break serializers: a null `endDate`, more
 * than one enum constant, an unconfirmed row, and records supplied out of order
 * so the sort in [ExportDocument] is exercised rather than assumed.
 */
internal object ExportFixture {

    val periods: List<PeriodRecord> = listOf(
        // Out of order on purpose — rule 4 says the file ascends.
        PeriodRecord(
            id = 3,
            startDate = LocalDate.of(2026, 6, 19),
            endDate = LocalDate.of(2026, 6, 24),
            source = PeriodRecordSource.NOTIFICATION_CONFIRMATION,
            isConfirmed = true,
        ),
        PeriodRecord(
            id = 1,
            startDate = LocalDate.of(2026, 4, 22),
            endDate = LocalDate.of(2026, 4, 27),
            source = PeriodRecordSource.HISTORICAL_ENTRY,
            isConfirmed = true,
        ),
        PeriodRecord(
            id = 4,
            startDate = LocalDate.of(2026, 7, 16),
            endDate = null,
            source = PeriodRecordSource.EDITED,
            isConfirmed = false,
        ),
        PeriodRecord(
            id = 2,
            startDate = LocalDate.of(2026, 5, 21),
            endDate = LocalDate.of(2026, 5, 25),
            source = PeriodRecordSource.MANUAL,
            isConfirmed = true,
        ),
    )

    val spotting: List<SpottingRecord> = listOf(
        SpottingRecord(id = 2, date = LocalDate.of(2026, 7, 13)),
        SpottingRecord(id = 1, date = LocalDate.of(2026, 5, 16)),
    )

    val settings = ExportedSettings(
        notificationPrivacy = "DISCREET",
        reminderTime = LocalTime.of(10, 0),
        periodApproaching = true,
        periodExpectedToday = true,
        didItStart = true,
        periodEndCheckIn = false,
        fertileWindow = false,
        ovulation = false,
        biometricUnlock = true,
        theme = "SYSTEM",
    )

    const val APP_VERSION = "0.1.0"
    val EXPORTED_ON: LocalDate = LocalDate.of(2026, 8, 19)

    fun render(): String = ExportDocument.render(
        periods = periods,
        spotting = spotting,
        settings = settings,
        appVersion = APP_VERSION,
        exportedOn = EXPORTED_ON,
    )
}
