package de.tsschulz.tt_tagebuch.shared.api

import de.tsschulz.tt_tagebuch.shared.api.http.PublicHttpClient
import de.tsschulz.tt_tagebuch.shared.api.models.ForgotPasswordRequest
import de.tsschulz.tt_tagebuch.shared.api.models.MessageResponse
import de.tsschulz.tt_tagebuch.shared.api.models.RegisterRequest
import de.tsschulz.tt_tagebuch.shared.api.models.ResetPasswordRequest
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.post
import io.ktor.client.request.setBody

class PublicAuthApi(
    private val client: PublicHttpClient,
) {
    suspend fun register(email: String, password: String) {
        client.http.post("/api/auth/register") {
            setBody(RegisterRequest(email = email, password = password))
        }
    }

    suspend fun activate(activationCode: String) {
        client.http.get("/api/auth/activate/$activationCode")
    }

    suspend fun forgotPassword(email: String): MessageResponse {
        return client.http.post("/api/auth/forgot-password") {
            setBody(ForgotPasswordRequest(email = email))
        }.body()
    }

    suspend fun resetPassword(token: String, password: String): MessageResponse {
        return client.http.post("/api/auth/reset-password") {
            setBody(ResetPasswordRequest(token = token, password = password))
        }.body()
    }
}
