package com.zyzf.coffeepreorder.database.model

import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverter
import androidx.room.TypeConverters

enum class RemoteKeyType(private val type: String) {
    COFFEE(Coffee::class.simpleName ?: "Coffee"),
    USER(User::class.simpleName ?: "User");

    @TypeConverter
    fun toRemoteKeyType(value: String) = entries.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?
)

