package de.tsschulz.tt_tagebuch.shared.api

import de.tsschulz.tt_tagebuch.shared.api.http.AuthedHttpClient
import de.tsschulz.tt_tagebuch.shared.api.models.TrainingCancellationDto
import de.tsschulz.tt_tagebuch.shared.api.models.TrainingCancellationUpsertBody
import io.ktor.client.call.body
import io.ktor.client.request.delete
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.contentType

class TrainingCancellationApi(
    private val client: AuthedHttpClient,
) {
    suspend fun list(clubId: Int, year: Int): List<TrainingCancellationDto> =
        client.http.get("/api/training-cancellations/$clubId") {
            parameter("year", year)
        }.body()

    suspend fun upsert(clubId: Int, body: TrainingCancellationUpsertBody): TrainingCancellationDto =
        client.http.post("/api/training-cancellations/$clubId") {
            contentType(ContentType.Application.Json)
            setBody(body)
        }.body()

    suspend fun delete(clubId: Int, cancellationId: Int) {
        client.http.delete("/api/training-cancellations/$clubId/$cancellationId")
    }
}
