package com.atridad.openclimb.data.database

import androidx.room.TypeConverter
import com.atridad.openclimb.data.model.*
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

class Converters {
    
    @TypeConverter
    fun fromClimbTypeList(value: List<ClimbType>): String {
        return Json.encodeToString(value)
    }
    
    @TypeConverter
    fun toClimbTypeList(value: String): List<ClimbType> {
        return Json.decodeFromString(value)
    }
    
    @TypeConverter
    fun fromDifficultySystemList(value: List<DifficultySystem>): String {
        return Json.encodeToString(value)
    }
    
    @TypeConverter
    fun toDifficultySystemList(value: String): List<DifficultySystem> {
        return Json.decodeFromString(value)
    }
    
    @TypeConverter
    fun fromStringList(value: List<String>): String {
        return Json.encodeToString(value)
    }
    
    @TypeConverter
    fun toStringList(value: String): List<String> {
        return Json.decodeFromString(value)
    }
    
    @TypeConverter
    fun fromDifficultyGrade(value: DifficultyGrade): String {
        return Json.encodeToString(value)
    }
    
    @TypeConverter
    fun toDifficultyGrade(value: String): DifficultyGrade {
        return Json.decodeFromString(value)
    }
    
    @TypeConverter
    fun fromClimbType(value: ClimbType): String {
        return value.name
    }
    
    @TypeConverter
    fun toClimbType(value: String): ClimbType {
        return ClimbType.valueOf(value)
    }
    
    @TypeConverter
    fun fromAttemptResult(value: AttemptResult): String {
        return value.name
    }
    
    @TypeConverter
    fun toAttemptResult(value: String): AttemptResult {
        return AttemptResult.valueOf(value)
    }
    
    @TypeConverter
    fun fromSessionStatus(value: SessionStatus): String {
        return value.name
    }
    
    @TypeConverter
    fun toSessionStatus(value: String): SessionStatus {
        return SessionStatus.valueOf(value)
    }

}
