package moe.lava.neon.api.endpoints

import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.request.parameter
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import kotlinx.serialization.Serializable
import moe.lava.neon.api.ApiClient
import moe.lava.neon.api.wrap

@Serializable
data class ExperimentResponse(
    val fingerprint: String,
)

@Serializable
private data class LoginRequest(
    val login: String,
    val password: String,
    val undelete: Boolean = false,
    val loginSource: String? = null,
    val giftCodeSkuId: String? = null,
)

@Serializable
data class LoginResponse(
    val userId: String,
    val token: String,
    val userSettings: UserSettings,
) {
    @Serializable
    data class UserSettings(val locale: String, val theme: String)
}

suspend fun ApiClient.getExperiments() = client.get("experiments") {
    parameter("with_guild_experiments", "true")
}.wrap<ExperimentResponse>()

suspend fun ApiClient.login(email: String, password: String, fingerprint: String) = client.post("auth/login") {
    header("X-Fingerprint", fingerprint)
    setBody(LoginRequest(
        login = email,
        password = password,
    ))
}.wrap<LoginResponse>()
