package de.tsschulz.tt_tagebuch.shared.api

import de.tsschulz.tt_tagebuch.shared.api.http.AuthedHttpClient
import de.tsschulz.tt_tagebuch.shared.api.models.AddDiaryMemberNoteBody
import de.tsschulz.tt_tagebuch.shared.api.models.DiaryMemberNoteDto
import de.tsschulz.tt_tagebuch.shared.api.models.DiaryMemberTagLinkDto
import de.tsschulz.tt_tagebuch.shared.api.models.DiaryMemberTagMutationBody
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

class DiaryMemberApi(
    private val client: AuthedHttpClient,
) {
    suspend fun listNotes(clubId: Int, diaryDateId: Int, memberId: Int): List<DiaryMemberNoteDto> {
        return client.http.get("/api/diarymember/$clubId/note") {
            parameter("diaryDateId", diaryDateId)
            parameter("memberId", memberId)
        }.body()
    }

    suspend fun addNote(clubId: Int, body: AddDiaryMemberNoteBody): List<DiaryMemberNoteDto> {
        return client.http.post("/api/diarymember/$clubId/note") {
            setBody(body)
        }.body()
    }

    suspend fun deleteNote(clubId: Int, noteId: Int, diaryDateId: Int, memberId: Int): List<DiaryMemberNoteDto> {
        return client.http.delete("/api/diarymember/$clubId/note/$noteId") {
            parameter("diaryDateId", diaryDateId)
            parameter("memberId", memberId)
        }.body()
    }

    suspend fun listTags(clubId: Int, diaryDateId: Int, memberId: Int): List<DiaryMemberTagLinkDto> {
        return client.http.get("/api/diarymember/$clubId/tag") {
            parameter("diaryDateId", diaryDateId)
            parameter("memberId", memberId)
        }.body()
    }

    suspend fun addTag(clubId: Int, body: DiaryMemberTagMutationBody): List<DiaryMemberTagLinkDto> {
        return client.http.post("/api/diarymember/$clubId/tag") {
            setBody(body)
        }.body()
    }

    suspend fun removeTag(clubId: Int, body: DiaryMemberTagMutationBody): List<DiaryMemberTagLinkDto> {
        return client.http.post("/api/diarymember/$clubId/tag/remove") {
            setBody(body)
        }.body()
    }
}
