// Code generated by moshi-kotlin-codegen. Do not edit.
@file:Suppress("DEPRECATION", "unused", "UNUSED_PARAMETER", "ClassName", "REDUNDANT_PROJECTION",
    "RedundantExplicitType", "LocalVariableName", "RedundantVisibilityModifier",
    "PLATFORM_CLASS_MAPPED_TO_KOTLIN", "IMPLICIT_NOTHING_TYPE_ARGUMENT_IN_RETURN_POSITION")

package com.rssuper.models

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.`internal`.Util
import java.lang.NullPointerException
import java.lang.reflect.Constructor
import java.util.Date
import kotlin.Double
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.collections.emptySet
import kotlin.jvm.Volatile
import kotlin.text.buildString

public class SearchResultJsonAdapter(
  moshi: Moshi,
) : JsonAdapter<SearchResult>() {
  private val options: JsonReader.Options = JsonReader.Options.of("id", "type", "title", "snippet",
      "link", "feedTitle", "published", "score")

  private val stringAdapter: JsonAdapter<String> = moshi.adapter(String::class.java, emptySet(),
      "id")

  private val searchResultTypeAdapter: JsonAdapter<SearchResultType> =
      moshi.adapter(SearchResultType::class.java, emptySet(), "type")

  private val nullableStringAdapter: JsonAdapter<String?> = moshi.adapter(String::class.java,
      emptySet(), "snippet")

  private val nullableDateAdapter: JsonAdapter<Date?> = moshi.adapter(Date::class.java, emptySet(),
      "published")

  private val nullableDoubleAdapter: JsonAdapter<Double?> =
      moshi.adapter(Double::class.javaObjectType, emptySet(), "score")

  @Volatile
  private var constructorRef: Constructor<SearchResult>? = null

  override fun toString(): String = buildString(34) {
      append("GeneratedJsonAdapter(").append("SearchResult").append(')') }

  override fun fromJson(reader: JsonReader): SearchResult {
    var id: String? = null
    var type: SearchResultType? = null
    var title: String? = null
    var snippet: String? = null
    var link: String? = null
    var feedTitle: String? = null
    var published: Date? = null
    var score: Double? = null
    var mask0 = -1
    reader.beginObject()
    while (reader.hasNext()) {
      when (reader.selectName(options)) {
        0 -> id = stringAdapter.fromJson(reader) ?: throw Util.unexpectedNull("id", "id", reader)
        1 -> type = searchResultTypeAdapter.fromJson(reader) ?: throw Util.unexpectedNull("type",
            "type", reader)
        2 -> title = stringAdapter.fromJson(reader) ?: throw Util.unexpectedNull("title", "title",
            reader)
        3 -> {
          snippet = nullableStringAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 3).inv()
          mask0 = mask0 and 0xfffffff7.toInt()
        }
        4 -> {
          link = nullableStringAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 4).inv()
          mask0 = mask0 and 0xffffffef.toInt()
        }
        5 -> {
          feedTitle = nullableStringAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 5).inv()
          mask0 = mask0 and 0xffffffdf.toInt()
        }
        6 -> {
          published = nullableDateAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 6).inv()
          mask0 = mask0 and 0xffffffbf.toInt()
        }
        7 -> {
          score = nullableDoubleAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 7).inv()
          mask0 = mask0 and 0xffffff7f.toInt()
        }
        -1 -> {
          // Unknown name, skip it.
          reader.skipName()
          reader.skipValue()
        }
      }
    }
    reader.endObject()
    if (mask0 == 0xffffff07.toInt()) {
      // All parameters with defaults are set, invoke the constructor directly
      return  SearchResult(
          id = id ?: throw Util.missingProperty("id", "id", reader),
          type = type ?: throw Util.missingProperty("type", "type", reader),
          title = title ?: throw Util.missingProperty("title", "title", reader),
          snippet = snippet,
          link = link,
          feedTitle = feedTitle,
          published = published,
          score = score
      )
    } else {
      // Reflectively invoke the synthetic defaults constructor
      @Suppress("UNCHECKED_CAST")
      val localConstructor: Constructor<SearchResult> = this.constructorRef ?:
          SearchResult::class.java.getDeclaredConstructor(String::class.java,
          SearchResultType::class.java, String::class.java, String::class.java, String::class.java,
          String::class.java, Date::class.java, Double::class.javaObjectType,
          Int::class.javaPrimitiveType, Util.DEFAULT_CONSTRUCTOR_MARKER).also {
          this.constructorRef = it }
      return localConstructor.newInstance(
          id ?: throw Util.missingProperty("id", "id", reader),
          type ?: throw Util.missingProperty("type", "type", reader),
          title ?: throw Util.missingProperty("title", "title", reader),
          snippet,
          link,
          feedTitle,
          published,
          score,
          mask0,
          /* DefaultConstructorMarker */ null
      )
    }
  }

  override fun toJson(writer: JsonWriter, value_: SearchResult?) {
    if (value_ == null) {
      throw NullPointerException("value_ was null! Wrap in .nullSafe() to write nullable values.")
    }
    writer.beginObject()
    writer.name("id")
    stringAdapter.toJson(writer, value_.id)
    writer.name("type")
    searchResultTypeAdapter.toJson(writer, value_.type)
    writer.name("title")
    stringAdapter.toJson(writer, value_.title)
    writer.name("snippet")
    nullableStringAdapter.toJson(writer, value_.snippet)
    writer.name("link")
    nullableStringAdapter.toJson(writer, value_.link)
    writer.name("feedTitle")
    nullableStringAdapter.toJson(writer, value_.feedTitle)
    writer.name("published")
    nullableDateAdapter.toJson(writer, value_.published)
    writer.name("score")
    nullableDoubleAdapter.toJson(writer, value_.score)
    writer.endObject()
  }
}
