package de.tsschulz.tt_tagebuch.shared.api

import de.tsschulz.tt_tagebuch.shared.api.http.AuthedHttpClient
import de.tsschulz.tt_tagebuch.shared.api.models.CreateTrainingGroupBody
import de.tsschulz.tt_tagebuch.shared.api.models.DeleteTrainingGroupBody
import de.tsschulz.tt_tagebuch.shared.api.models.DiaryPlanGroup
import de.tsschulz.tt_tagebuch.shared.api.models.UpdateTrainingGroupBody
import io.ktor.client.call.body
import io.ktor.client.request.delete
import io.ktor.client.request.get
import io.ktor.client.request.post
import io.ktor.client.request.put
import io.ktor.client.request.setBody

/**
 * Trainingsgruppen am Tagebuch-Tag (`/api/group`), für gruppenbezogene Plan-Einträge.
 */
class GroupApi(
    private val client: AuthedHttpClient,
) {
    suspend fun listForDiaryDate(clubId: Int, diaryDateId: Int): List<DiaryPlanGroup> {
        return client.http.get("/api/group/$clubId/$diaryDateId").body()
    }

    suspend fun create(body: CreateTrainingGroupBody): DiaryPlanGroup {
        return client.http.post("/api/group") {
            setBody(body)
        }.body()
    }

    suspend fun update(groupId: Int, body: UpdateTrainingGroupBody): DiaryPlanGroup {
        return client.http.put("/api/group/$groupId") {
            setBody(body)
        }.body()
    }

    suspend fun delete(groupId: Int, body: DeleteTrainingGroupBody) {
        client.http.delete("/api/group/$groupId") {
            setBody(body)
        }
    }
}
