/**
 * OpenAPI Petstore
 *
 * Test for issue 4062
 *
 * The version of the OpenAPI document: 1.0.0
 * 
 *
 * Please note:
 * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * Do not edit this file manually.
 */

@file:Suppress(
    "ArrayInDataClass",
    "EnumEntryName",
    "RemoveRedundantQualifierName",
    "UnusedImport"
)

package org.openapitools.client.models


import com.squareup.moshi.Json

/**
 * An enum with complex-ish naming
 *
 * Values: MY_FIRST_VALUE,MY_SECOND_VALUE
 */

enum class PetEnum(val value: kotlin.String) {

    @Json(name = "myFirstValue")
    MY_FIRST_VALUE("myFirstValue"),

    @Json(name = "MY_SECOND_VALUE")
    MY_SECOND_VALUE("MY_SECOND_VALUE");

    /**
     * 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(): String = value

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

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

