package de.trainingstagebuch.app.services

import de.trainingstagebuch.app.repository.ClubLeaguesResult
import de.trainingstagebuch.app.repository.ClubTeamActionResult
import de.trainingstagebuch.app.repository.ClubTeamsResult
import de.trainingstagebuch.app.repository.MyTischtennisActionResult
import de.trainingstagebuch.app.repository.SchedulerJobsResult
import de.trainingstagebuch.app.repository.TeamDocumentParseResult
import de.trainingstagebuch.app.repository.TeamDocumentUploadResult
import de.trainingstagebuch.app.repository.TeamDocumentsResult
import de.trainingstagebuch.app.repository.TeamPlayerStatsResult
import de.trainingstagebuch.app.repository.TrainingstagebuchRepository

class TeamManagementService(
    private val repository: TrainingstagebuchRepository
) {
    suspend fun loadTeams(clubId: String, seasonId: String? = null): ClubTeamsResult =
        repository.loadClubTeams(clubId = clubId, seasonId = seasonId)

    suspend fun loadLeagues(clubId: String, seasonId: String? = null): ClubLeaguesResult =
        repository.loadClubLeagues(clubId = clubId, seasonId = seasonId)

    suspend fun createTeam(clubId: String, name: String, leagueId: String?, seasonId: String): ClubTeamActionResult =
        repository.createClubTeam(clubId = clubId, name = name, leagueId = leagueId, seasonId = seasonId)

    suspend fun updateTeam(teamId: String, name: String, leagueId: String?, seasonId: String): ClubTeamActionResult =
        repository.updateClubTeam(clubTeamId = teamId, name = name, leagueId = leagueId, seasonId = seasonId)

    suspend fun deleteTeam(teamId: String): ClubTeamActionResult = repository.deleteClubTeam(teamId)

    suspend fun loadTeamDocuments(teamId: String): TeamDocumentsResult = repository.loadTeamDocuments(teamId)

    suspend fun parseTeamDocument(documentId: String, leagueId: String): TeamDocumentParseResult =
        repository.parseTeamDocument(documentId = documentId, leagueId = leagueId)

    suspend fun uploadTeamDocument(
        clubTeamId: String,
        documentType: String,
        fileName: String,
        bytes: ByteArray
    ): TeamDocumentUploadResult = repository.uploadTeamDocument(
        clubTeamId = clubTeamId,
        documentType = documentType,
        fileName = fileName,
        bytes = bytes
    )

    suspend fun loadSchedulerJobs(clubId: String?): SchedulerJobsResult = repository.loadSchedulerJobs(clubId)

    suspend fun loadPlayerStats(clubId: String, leagueId: String, seasonId: String?): TeamPlayerStatsResult =
        repository.loadTeamPlayerStats(clubId = clubId, leagueId = leagueId, seasonId = seasonId)

    suspend fun parseMyTischtennisUrl(url: String): MyTischtennisActionResult = repository.parseMyTischtennisUrl(url)

    suspend fun configureMyTischtennisTeam(url: String, clubTeamId: String): MyTischtennisActionResult =
        repository.configureMyTischtennisTeam(url = url, clubTeamId = clubTeamId)

    suspend fun configureMyTischtennisLeague(url: String): MyTischtennisActionResult =
        repository.configureMyTischtennisLeague(url = url)

    suspend fun startFetchTeamDataJob(clubTeamId: String): MyTischtennisActionResult =
        repository.startMyTischtennisFetchJob(clubTeamId)

    suspend fun getFetchTeamDataJob(jobId: String): MyTischtennisActionResult =
        repository.getMyTischtennisFetchJob(jobId)
}
