package de.tsschulz.tt_tagebuch.shared.repository

import de.tsschulz.tt_tagebuch.shared.api.ApiClient
import de.tsschulz.tt_tagebuch.shared.api.SocketService
import de.tsschulz.tt_tagebuch.shared.models.DiaryDate
import kotlinx.coroutines.flow.Flow
import org.json.JSONObject

class DiaryRepository(
    private val apiClient: ApiClient,
    private val socketService: SocketService
) {
    suspend fun getDiaryDates(clubId: Int): List<DiaryDate> {
        return apiClient.getDiaryDates(clubId)
    }

    suspend fun getParticipants(dateId: Int): List<de.tsschulz.tt_tagebuch.shared.models.Participant> {
        return apiClient.getDiaryParticipants(dateId)
    }

    suspend fun updateParticipantStatus(dateId: Int, memberId: Int, status: String): Boolean {
        return apiClient.updateParticipantStatus(dateId, memberId, status)
    }

    suspend fun getMembers(clubId: Int): List<de.tsschulz.tt_tagebuch.shared.models.Member> {
        return apiClient.getMembers(clubId)
    }

    fun observeEvents(): Flow<Pair<String, JSONObject>> {
        return socketService.events
    }

    fun connectSocket(clubId: Int) {
        socketService.connect(clubId)
    }

    fun disconnectSocket() {
        socketService.disconnect()
    }
}
