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

package dev.mokksy.aimocks.openai.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
 * The error code for the response.
 */
@Serializable
public enum class ResponseErrorCode(
    public val value: String,
) {
    @SerialName(value = "server_error")
    SERVER_ERROR("server_error"),

    @SerialName(value = "rate_limit_exceeded")
    RATE_LIMIT_EXCEEDED("rate_limit_exceeded"),

    @SerialName(value = "invalid_prompt")
    INVALID_PROMPT("invalid_prompt"),

    @SerialName(value = "vector_store_timeout")
    VECTOR_STORE_TIMEOUT("vector_store_timeout"),

    @SerialName(value = "invalid_image")
    INVALID_IMAGE("invalid_image"),

    @SerialName(value = "invalid_image_format")
    INVALID_IMAGE_FORMAT("invalid_image_format"),

    @SerialName(value = "invalid_base64_image")
    INVALID_BASE64_IMAGE("invalid_base64_image"),

    @SerialName(value = "invalid_image_url")
    INVALID_IMAGE_URL("invalid_image_url"),

    @SerialName(value = "image_too_large")
    IMAGE_TOO_LARGE("image_too_large"),

    @SerialName(value = "image_too_small")
    IMAGE_TOO_SMALL("image_too_small"),

    @SerialName(value = "image_parse_error")
    IMAGE_PARSE_ERROR("image_parse_error"),

    @SerialName(value = "image_content_policy_violation")
    IMAGE_CONTENT_POLICY_VIOLATION("image_content_policy_violation"),

    @SerialName(value = "invalid_image_mode")
    INVALID_IMAGE_MODE("invalid_image_mode"),

    @SerialName(value = "image_file_too_large")
    IMAGE_FILE_TOO_LARGE("image_file_too_large"),

    @SerialName(value = "unsupported_image_media_type")
    UNSUPPORTED_IMAGE_MEDIA_TYPE("unsupported_image_media_type"),

    @SerialName(value = "empty_image_file")
    EMPTY_IMAGE_FILE("empty_image_file"),

    @SerialName(value = "failed_to_download_image")
    FAILED_TO_DOWNLOAD_IMAGE("failed_to_download_image"),

    @SerialName(value = "image_file_not_found")
    IMAGE_FILE_NOT_FOUND("image_file_not_found"),
    ;

    /**
     * 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

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

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