package de.trainingstagebuch.app.services

import de.trainingstagebuch.app.repository.DomainSocketEvent
import de.trainingstagebuch.app.repository.MembersResult
import de.trainingstagebuch.app.repository.ScheduleActionResult
import de.trainingstagebuch.app.repository.ScheduleLeagueTableResult
import de.trainingstagebuch.app.repository.ScheduleMatchesResult
import de.trainingstagebuch.app.repository.ScheduleTeamsResult
import de.trainingstagebuch.app.repository.TrainingstagebuchRepository
import kotlinx.coroutines.flow.SharedFlow

class ScheduleService(
    private val repository: TrainingstagebuchRepository
) {
    val socketEvents: SharedFlow<DomainSocketEvent> = repository.socketDomainEvents

    suspend fun loadTeams(clubId: String, seasonId: String? = null): ScheduleTeamsResult =
        repository.loadScheduleTeams(clubId, seasonId)

    suspend fun loadMatches(clubId: String, leagueId: String? = null, seasonId: String? = null): ScheduleMatchesResult =
        repository.loadScheduleMatches(clubId, leagueId, seasonId)

    suspend fun loadLeagueTable(clubId: String, leagueId: String): ScheduleLeagueTableResult =
        repository.loadLeagueTable(clubId, leagueId)

    suspend fun loadMembers(clubId: String): MembersResult = repository.loadMembers(clubId, showAll = true)

    suspend fun saveMatchPlayers(
        matchId: String,
        clubId: String,
        playersReady: List<String>,
        playersPlanned: List<String>,
        playersPlayed: List<String>
    ): ScheduleActionResult = repository.updateMatchPlayers(
        matchId = matchId,
        clubId = clubId,
        playersReady = playersReady,
        playersPlanned = playersPlanned,
        playersPlayed = playersPlayed
    )
}
