package io.dico.parcels2.storage import io.dico.parcels2.* import kotlinx.coroutines.Deferred import kotlinx.coroutines.Job import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.channels.SendChannel import org.joda.time.DateTime import java.util.UUID import kotlin.coroutines.CoroutineContext interface Backing { val name: String val isConnected: Boolean val coroutineContext: CoroutineContext fun launchJob(job: Backing.() -> Unit): Job fun launchFuture(future: Backing.() -> T): Deferred fun openChannel(future: Backing.(SendChannel) -> Unit): ReceiveChannel fun openChannelForWriting(future: Backing.(T) -> Unit): SendChannel fun init() fun shutdown() fun getWorldCreationTime(worldId: ParcelWorldId): DateTime? fun setWorldCreationTime(worldId: ParcelWorldId, time: DateTime) fun getPlayerUuidForName(name: String): UUID? fun updatePlayerName(uuid: UUID, name: String) fun transmitParcelData(channel: SendChannel, parcels: Sequence) fun transmitAllParcelData(channel: SendChannel) fun readParcelData(parcel: ParcelId): ParcelDataHolder? fun getOwnedParcels(user: PlayerProfile): List fun getNumParcels(user: PlayerProfile): Int = getOwnedParcels(user).size fun setParcelData(parcel: ParcelId, data: ParcelDataHolder?) fun setParcelOwner(parcel: ParcelId, owner: PlayerProfile?) fun setParcelOwnerSignOutdated(parcel: ParcelId, outdated: Boolean) fun setLocalPrivilege(parcel: ParcelId, player: PlayerProfile, privilege: Privilege) fun setParcelOptionsInteractConfig(parcel: ParcelId, config: InteractableConfiguration) fun transmitAllGlobalPrivileges(channel: SendChannel>) fun readGlobalPrivileges(owner: PlayerProfile): PrivilegesHolder? fun setGlobalPrivilege(owner: PlayerProfile, player: PlayerProfile, privilege: Privilege) }