package de.trainingstagebuch.app.services

import de.trainingstagebuch.app.repository.MembersResult
import de.trainingstagebuch.app.repository.MemberSaveResult
import de.trainingstagebuch.app.repository.MemberActionResult
import de.trainingstagebuch.app.repository.MemberImagesResult
import de.trainingstagebuch.app.repository.MemberContactItem
import de.trainingstagebuch.app.repository.MemberNotesResult
import de.trainingstagebuch.app.repository.MemberTrainingGroupsResult
import de.trainingstagebuch.app.repository.TrainingstagebuchRepository

class MembersService(
    private val repository: TrainingstagebuchRepository
) {
    suspend fun loadMembers(clubId: String, showAll: Boolean = true): MembersResult {
        return repository.loadMembers(clubId = clubId, showAll = showAll)
    }

    suspend fun saveMember(
        clubId: String,
        memberId: String?,
        firstName: String,
        lastName: String,
        active: Boolean,
        testMembership: Boolean,
        contacts: List<MemberContactItem>
    ): MemberSaveResult {
        return repository.saveMember(
            clubId = clubId,
            memberId = memberId,
            firstName = firstName,
            lastName = lastName,
            active = active,
            testMembership = testMembership,
            contacts = contacts
        )
    }

    suspend fun quickRemoveTestMembership(clubId: String, memberId: String): MemberActionResult {
        return repository.quickRemoveTestMembership(clubId = clubId, memberId = memberId)
    }

    suspend fun quickDeactivateMember(clubId: String, memberId: String): MemberActionResult {
        return repository.quickDeactivateMember(clubId = clubId, memberId = memberId)
    }

    suspend fun loadMemberImages(clubId: String, memberId: String): MemberImagesResult {
        return repository.loadMemberImages(clubId = clubId, memberId = memberId)
    }

    suspend fun uploadMemberImage(
        clubId: String,
        memberId: String,
        fileName: String,
        bytes: ByteArray
    ): MemberActionResult {
        return repository.uploadMemberImage(
            clubId = clubId,
            memberId = memberId,
            fileName = fileName,
            bytes = bytes
        )
    }

    suspend fun setPrimaryMemberImage(
        clubId: String,
        memberId: String,
        imageId: String
    ): MemberActionResult {
        return repository.setPrimaryMemberImage(clubId = clubId, memberId = memberId, imageId = imageId)
    }

    suspend fun deleteMemberImage(
        clubId: String,
        memberId: String,
        imageId: String
    ): MemberActionResult {
        return repository.deleteMemberImage(clubId = clubId, memberId = memberId, imageId = imageId)
    }

    suspend fun loadTrainingGroups(clubId: String): MemberTrainingGroupsResult {
        return repository.loadTrainingGroups(clubId = clubId)
    }

    suspend fun loadMemberTrainingGroups(clubId: String, memberId: String): MemberTrainingGroupsResult {
        return repository.loadMemberTrainingGroups(clubId = clubId, memberId = memberId)
    }

    suspend fun addMemberToTrainingGroup(
        clubId: String,
        memberId: String,
        groupId: String
    ): MemberActionResult {
        return repository.addMemberToTrainingGroup(clubId = clubId, memberId = memberId, groupId = groupId)
    }

    suspend fun removeMemberFromTrainingGroup(
        clubId: String,
        memberId: String,
        groupId: String
    ): MemberActionResult {
        return repository.removeMemberFromTrainingGroup(clubId = clubId, memberId = memberId, groupId = groupId)
    }

    suspend fun loadMemberNotes(clubId: String, memberId: String): MemberNotesResult {
        return repository.loadMemberNotes(clubId = clubId, memberId = memberId)
    }

    suspend fun addMemberNote(clubId: String, memberId: String, content: String): MemberNotesResult {
        return repository.addMemberNote(clubId = clubId, memberId = memberId, content = content)
    }

    suspend fun deleteMemberNote(clubId: String, noteId: String): MemberNotesResult {
        return repository.deleteMemberNote(clubId = clubId, noteId = noteId)
    }

    suspend fun updateRatings(clubId: String): MemberActionResult {
        return repository.updateMemberRatings(clubId = clubId)
    }
}
