// 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 kotlin.Int
import kotlin.Long
import kotlin.String
import kotlin.Suppress
import kotlin.collections.emptySet
import kotlin.jvm.Volatile
import kotlin.text.buildString

public class EnclosureJsonAdapter(
  moshi: Moshi,
) : JsonAdapter<Enclosure>() {
  private val options: JsonReader.Options = JsonReader.Options.of("url", "type", "length")

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

  private val nullableLongAdapter: JsonAdapter<Long?> = moshi.adapter(Long::class.javaObjectType,
      emptySet(), "length")

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

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

  override fun fromJson(reader: JsonReader): Enclosure {
    var url: String? = null
    var type: String? = null
    var length: Long? = null
    var mask0 = -1
    reader.beginObject()
    while (reader.hasNext()) {
      when (reader.selectName(options)) {
        0 -> url = stringAdapter.fromJson(reader) ?: throw Util.unexpectedNull("url", "url", reader)
        1 -> type = stringAdapter.fromJson(reader) ?: throw Util.unexpectedNull("type", "type",
            reader)
        2 -> {
          length = nullableLongAdapter.fromJson(reader)
          // $mask = $mask and (1 shl 2).inv()
          mask0 = mask0 and 0xfffffffb.toInt()
        }
        -1 -> {
          // Unknown name, skip it.
          reader.skipName()
          reader.skipValue()
        }
      }
    }
    reader.endObject()
    if (mask0 == 0xfffffffb.toInt()) {
      // All parameters with defaults are set, invoke the constructor directly
      return  Enclosure(
          url = url ?: throw Util.missingProperty("url", "url", reader),
          type = type ?: throw Util.missingProperty("type", "type", reader),
          length = length
      )
    } else {
      // Reflectively invoke the synthetic defaults constructor
      @Suppress("UNCHECKED_CAST")
      val localConstructor: Constructor<Enclosure> = this.constructorRef ?:
          Enclosure::class.java.getDeclaredConstructor(String::class.java, String::class.java,
          Long::class.javaObjectType, Int::class.javaPrimitiveType,
          Util.DEFAULT_CONSTRUCTOR_MARKER).also { this.constructorRef = it }
      return localConstructor.newInstance(
          url ?: throw Util.missingProperty("url", "url", reader),
          type ?: throw Util.missingProperty("type", "type", reader),
          length,
          mask0,
          /* DefaultConstructorMarker */ null
      )
    }
  }

  override fun toJson(writer: JsonWriter, value_: Enclosure?) {
    if (value_ == null) {
      throw NullPointerException("value_ was null! Wrap in .nullSafe() to write nullable values.")
    }
    writer.beginObject()
    writer.name("url")
    stringAdapter.toJson(writer, value_.url)
    writer.name("type")
    stringAdapter.toJson(writer, value_.type)
    writer.name("length")
    nullableLongAdapter.toJson(writer, value_.length)
    writer.endObject()
  }
}
