package com.prodhack.moscow2025.data.data_providers.local_db.entities

import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.prodhack.moscow2025.domain.models.Education
import com.prodhack.moscow2025.domain.models.Project
import com.prodhack.moscow2025.domain.models.WorkExperience

object JsonTypeConverters {

    private val gson = Gson()

    @TypeConverter
    fun fromWorkExperienceList(value: List<WorkExperience>): String {
        val type = object : TypeToken<List<WorkExperience>>() {}.type
        return gson.toJson(value, type)
    }

    @TypeConverter
    fun toWorkExperienceList(value: String): List<WorkExperience> {
        val type = object : TypeToken<List<WorkExperience>>() {}.type
        return gson.fromJson(value, type)
    }

    @TypeConverter
    fun fromEducationList(value: List<Education>): String {
        val type = object : TypeToken<List<Education>>() {}.type
        return gson.toJson(value, type)
    }

    @TypeConverter
    fun toEducationList(value: String): List<Education> {
        val type = object : TypeToken<List<Education>>() {}.type
        return gson.fromJson(value, type)
    }

    @TypeConverter
    fun fromProjectList(value: List<Project>): String {
        val type = object : TypeToken<List<Project>>() {}.type
        return gson.toJson(value, type)
    }

    @TypeConverter
    fun toProjectList(value: String): List<Project> {
        val type = object : TypeToken<List<Project>>() {}.type
        return gson.fromJson(value, type)
    }
}
