package de.tsschulz.tt_tagebuch.shared.api

import de.tsschulz.tt_tagebuch.shared.api.http.AuthedHttpClient
import de.tsschulz.tt_tagebuch.shared.api.models.DeleteAccountRequest
import de.tsschulz.tt_tagebuch.shared.api.models.LoginRequest
import de.tsschulz.tt_tagebuch.shared.api.models.LoginResponse
import io.ktor.client.call.body
import io.ktor.client.request.delete
import io.ktor.client.request.post
import io.ktor.client.request.setBody

class AuthApi(
    private val client: AuthedHttpClient,
) {
    suspend fun login(email: String, password: String): LoginResponse {
        return client.http.post("/api/auth/login") {
            setBody(LoginRequest(email = email, password = password, rememberMe = true))
        }.body()
    }

    suspend fun logout() {
        client.http.post("/api/auth/logout")
    }

    suspend fun deleteAccount(password: String) {
        client.http.delete("/api/auth/account") {
            setBody(DeleteAccountRequest(password = password))
        }
    }
}
