package com.example.myapplication.database.remotekeys.model

import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import com.example.myapplication.database.entities.model.Bike
import com.example.myapplication.database.entities.model.Rent
import com.example.myapplication.database.entities.model.Item

enum class RemoteKeyType(private val type: String) {
    CINEMA(Bike::class.simpleName ?: "Bike"),
    ORDER(Rent::class.simpleName ?: "Rent"),
    SESSION(Item::class.simpleName ?: "Item");

    @TypeConverter
    fun toRemoteKeyType(value: String) = RemoteKeyType.values().first { it.type == value }

    @TypeConverter
    fun fromRemoteKeyType(value: RemoteKeyType) = value.type
}

@Entity(tableName = "remote_keys")
data class RemoteKeys(
    @PrimaryKey val entityId: Int,
    @TypeConverters(RemoteKeyType::class)
    val type: RemoteKeyType,
    val prevKey: Int?,
    val nextKey: Int?
)
