package com.zaojiao.app.core.json.adapter

import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonQualifier
import com.squareup.moshi.ToJson

@Retention(value = AnnotationRetention.RUNTIME)
@JsonQualifier
annotation class HexColor

class  HexColorAdapter {
    @ToJson
    fun toJson(@HexColor rgb: Int): String {
        return "#%06x".format(rgb)
    }

    @FromJson
    @HexColor
    fun fromJson(rgb: String): Int {
        return rgb.substring(1).toInt(16)
    }
}