package com.zaojiao.http.converter

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

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

internal 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)
    }
}