package de.tsschulz.tt_tagebuch.shared.api

import de.tsschulz.tt_tagebuch.shared.api.http.AuthedHttpClient
import de.tsschulz.tt_tagebuch.shared.api.models.AddMemberActivityParticipantsBody
import de.tsschulz.tt_tagebuch.shared.api.models.DiaryMemberActivityLink
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.setBody

class DiaryMemberActivitiesApi(
    private val client: AuthedHttpClient,
) {
    suspend fun list(clubId: Int, diaryDateOrGroupActivityId: Int): List<DiaryMemberActivityLink> {
        return client.http.get("/api/diary-member-activities/$clubId/$diaryDateOrGroupActivityId").body()
    }

    suspend fun add(clubId: Int, diaryDateOrGroupActivityId: Int, participantIds: List<Int>) {
        client.http.post("/api/diary-member-activities/$clubId/$diaryDateOrGroupActivityId") {
            setBody(AddMemberActivityParticipantsBody(participantIds = participantIds))
        }
    }

    suspend fun remove(clubId: Int, diaryDateOrGroupActivityId: Int, participantRowId: Int) {
        client.http.delete("/api/diary-member-activities/$clubId/$diaryDateOrGroupActivityId/$participantRowId")
    }
}
