package de.trainingstagebuch.app.services

import de.trainingstagebuch.app.repository.PermissionActionResult
import de.trainingstagebuch.app.repository.PermissionMembersResult
import de.trainingstagebuch.app.repository.PermissionRolesResult
import de.trainingstagebuch.app.repository.PermissionStructureResult
import de.trainingstagebuch.app.repository.TrainingstagebuchRepository

class PermissionsService(
    private val repository: TrainingstagebuchRepository
) {
    suspend fun loadRoles(): PermissionRolesResult = repository.loadPermissionRoles()

    suspend fun loadStructure(): PermissionStructureResult = repository.loadPermissionStructure()

    suspend fun loadMembers(clubId: String, cacheBust: Long? = null): PermissionMembersResult =
        repository.loadPermissionMembers(clubId = clubId, cacheBust = cacheBust)

    suspend fun updateRole(clubId: String, userId: String, role: String): PermissionActionResult =
        repository.updatePermissionUserRole(clubId = clubId, userId = userId, role = role)

    suspend fun updateStatus(clubId: String, userId: String, approved: Boolean): PermissionActionResult =
        repository.updatePermissionUserStatus(clubId = clubId, userId = userId, approved = approved)

    suspend fun updatePermissions(
        clubId: String,
        userId: String,
        permissions: Map<String, Map<String, Boolean>>
    ): PermissionActionResult = repository.updatePermissionUserPermissions(
        clubId = clubId,
        userId = userId,
        permissions = permissions
    )
}
