package com.rssuper.converters

import androidx.room.TypeConverter
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import com.rssuper.models.FeedItem

class FeedItemListConverter {
    private val moshi = Moshi.Builder()
        .add(KotlinJsonAdapterFactory())
        .build()
    private val adapter = moshi.adapter(List::class.java)

    @TypeConverter
    fun fromFeedItemList(value: List<FeedItem>?): String? {
        return value?.let { adapter.toJson(it) }
    }

    @TypeConverter
    fun toFeedItemList(value: String?): List<FeedItem>? {
        return value?.let { adapter.fromJson(it) }
    }
}
