package com.tt.honeyDue.fixtures

import com.tt.honeyDue.models.ResidenceCreateRequest
import kotlin.random.Random

/**
 * Test residence fixture mirroring `TestFixtures.TestResidence` in Swift.
 * Produces the exact payload shape the Go API expects so seed tests can
 * call `APILayer.createResidence(fixture.toCreateRequest())`.
 */
data class TestResidence(
    val name: String,
    val streetAddress: String,
    val city: String,
    val stateProvince: String,
    val postalCode: String,
    val country: String = "USA",
    val bedrooms: Int? = null,
    val bathrooms: Double? = null,
    val isPrimary: Boolean = false,
) {
    fun toCreateRequest(): ResidenceCreateRequest = ResidenceCreateRequest(
        name = name,
        streetAddress = streetAddress,
        city = city,
        stateProvince = stateProvince,
        postalCode = postalCode,
        country = country,
        bedrooms = bedrooms,
        bathrooms = bathrooms,
        isPrimary = isPrimary,
    )

    companion object {
        fun house(suffix: String = randomSuffix()): TestResidence = TestResidence(
            name = "Test House $suffix",
            streetAddress = "123 Test St",
            city = "Testville",
            stateProvince = "CA",
            postalCode = "94000",
            bedrooms = 3,
            bathrooms = 2.0,
            isPrimary = true,
        )

        fun apartment(suffix: String = randomSuffix()): TestResidence = TestResidence(
            name = "Test Apt $suffix",
            streetAddress = "456 Mock Ave",
            city = "Testville",
            stateProvince = "CA",
            postalCode = "94001",
            bedrooms = 1,
            bathrooms = 1.0,
            isPrimary = false,
        )

        private fun randomSuffix(): String =
            Random.nextInt(1000, 9999).toString()
    }
}
