/**
 *
 * Please note:
 * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * Do not edit this file manually.
 *
 */
package com.gravatar.restapi.models

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

/**
 * Rating associated with the image.
 *
 * Values: G,PG,R,X
 */

@JsonClass(generateAdapter = false)
public enum class Rating(public val value: kotlin.String) {
    @Json(name = "G")
    G("G"),

    @Json(name = "PG")
    PG("PG"),

    @Json(name = "R")
    R("R"),

    @Json(name = "X")
    X("X"),
    ;

    /**
     * Override [toString()] to avoid using the enum variable name as the value, and instead use
     * the actual value defined in the API spec file.
     *
     * This solves a problem when the variable name and its value are different, and ensures that
     * the client sends the correct enum values to the server always.
     */
    override fun toString(): kotlin.String = value

    public companion object {
        /**
         * Converts the provided [data] to a [String] on success, null otherwise.
         */
        public fun encode(data: kotlin.Any?): kotlin.String? = if (data is Rating) "$data" else null

        /**
         * Returns a valid [Rating] for [data], null otherwise.
         */
        public fun decode(data: kotlin.Any?): Rating? = data?.let {
            val normalizedData = "$it".lowercase()
            values().firstOrNull { value ->
                it == value || normalizedData == "$value".lowercase()
            }
        }
    }
}
