(function (_, kotlin_kotlin, kotlin_org_jetbrains_kotlinx_kotlinx_serialization_json, kotlin_io_ktor_ktor_http, kotlin_org_jetbrains_kotlinx_kotlinx_serialization_core, kotlin_io_ktor_ktor_client_json) {
  'use strict';
  //region block: imports
  var Unit_getInstance = kotlin_kotlin.$_$.i6;
  var VOID = kotlin_kotlin.$_$.g;
  var Json = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_json.$_$.p;
  var protoOf = kotlin_kotlin.$_$.bg;
  var objectMeta = kotlin_kotlin.$_$.ag;
  var setMetadataFor = kotlin_kotlin.$_$.cg;
  var TextContent = kotlin_io_ktor_ktor_http.$_$.u;
  var serializer = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_core.$_$.y3;
  var serializer_0 = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_core.$_$.z3;
  var ensureNotNull = kotlin_kotlin.$_$.in;
  var write = kotlin_io_ktor_ktor_client_json.$_$.a;
  var JsonSerializer = kotlin_io_ktor_ktor_client_json.$_$.b;
  var classMeta = kotlin_kotlin.$_$.me;
  var getKClassFromExpression = kotlin_kotlin.$_$.d;
  var MapSerializer = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_core.$_$.z;
  var Map = kotlin_kotlin.$_$.d7;
  var isInterface = kotlin_kotlin.$_$.lf;
  var SetSerializer = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_core.$_$.a1;
  var Set = kotlin_kotlin.$_$.m7;
  var firstOrNull = kotlin_kotlin.$_$.q9;
  var StringCompanionObject_getInstance = kotlin_kotlin.$_$.v5;
  var serializer_1 = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_core.$_$.c1;
  var ListSerializer = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_core.$_$.y;
  var isArray = kotlin_kotlin.$_$.df;
  var List = kotlin_kotlin.$_$.b7;
  var Companion_getInstance = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_json.$_$.b;
  var JsonElement = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_json.$_$.j;
  var THROW_CCE = kotlin_kotlin.$_$.nm;
  var KSerializer = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_core.$_$.o3;
  var filterNotNull = kotlin_kotlin.$_$.m9;
  var collectionSizeOrDefault = kotlin_kotlin.$_$.b8;
  var ArrayList_init_$Create$ = kotlin_kotlin.$_$.p;
  var HashSet_init_$Create$ = kotlin_kotlin.$_$.x;
  var ArrayList_init_$Create$_0 = kotlin_kotlin.$_$.q;
  var toString = kotlin_kotlin.$_$.gg;
  var IllegalStateException_init_$Create$ = kotlin_kotlin.$_$.m2;
  var singleOrNull = kotlin_kotlin.$_$.yb;
  var Collection = kotlin_kotlin.$_$.r6;
  var get_nullable = kotlin_org_jetbrains_kotlinx_kotlinx_serialization_core.$_$.b1;
  var get_serializersStore = kotlin_io_ktor_ktor_client_json.$_$.c;
  //endregion
  //region block: pre-declaration
  setMetadataFor(Companion, 'Companion', objectMeta);
  setMetadataFor(KotlinxSerializer, 'KotlinxSerializer', classMeta, VOID, [JsonSerializer], KotlinxSerializer);
  setMetadataFor(SerializerInitializer, 'SerializerInitializer', objectMeta);
  //endregion
  function KotlinxSerializer$Companion$DefaultJson$lambda($this$Json) {
    $this$Json.set_isLenient_kuajk5_k$(false);
    $this$Json.set_ignoreUnknownKeys_pzvtne_k$(false);
    $this$Json.set_allowSpecialFloatingPointValues_xyc2ru_k$(true);
    $this$Json.set_useArrayPolymorphism_54w3tr_k$(false);
    return Unit_getInstance();
  }
  function _get_json__d8whur($this) {
    return $this.json_1;
  }
  function Companion() {
    Companion_instance = this;
    var tmp = this;
    tmp.DefaultJson_1 = Json(VOID, KotlinxSerializer$Companion$DefaultJson$lambda);
  }
  protoOf(Companion).get_DefaultJson_y8vsqo_k$ = function () {
    return this.DefaultJson_1;
  };
  var Companion_instance;
  function Companion_getInstance_0() {
    if (Companion_instance == null)
      new Companion();
    return Companion_instance;
  }
  function KotlinxSerializer(json) {
    Companion_getInstance_0();
    json = json === VOID ? Companion_getInstance_0().DefaultJson_1 : json;
    this.json_1 = json;
  }
  protoOf(KotlinxSerializer).write_508nyz_k$ = function (data, contentType) {
    return new TextContent(this.writeContent_v4avoc_k$(data), contentType);
  };
  protoOf(KotlinxSerializer).writeContent_v4avoc_k$ = function (data) {
    return this.json_1.encodeToString_k0apqx_k$(buildSerializer(data, this.json_1.get_serializersModule_piitvg_k$()), data);
  };
  protoOf(KotlinxSerializer).read_dvvuuy_k$ = function (type, body) {
    var text = body.readText$default_grxas_k$();
    var deserializationStrategy = this.json_1.get_serializersModule_piitvg_k$().getContextual$default_o8kdzb_k$(type.get_type_wovaf7_k$());
    var tmp;
    if (deserializationStrategy == null) {
      var tmp0_safe_receiver = type.get_kotlinType_flgmsk_k$();
      var tmp_0;
      if (tmp0_safe_receiver == null) {
        tmp_0 = null;
      } else {
        // Inline function 'kotlin.let' call
        // Inline function 'kotlin.contracts.contract' call
        // Inline function 'io.ktor.client.plugins.kotlinx.serializer.KotlinxSerializer.read.<anonymous>' call
        tmp_0 = serializer(tmp0_safe_receiver);
      }
      var tmp1_elvis_lhs = tmp_0;
      tmp = tmp1_elvis_lhs == null ? serializer_0(type.get_type_wovaf7_k$()) : tmp1_elvis_lhs;
    } else {
      tmp = deserializationStrategy;
    }
    var mapper = tmp;
    return ensureNotNull(this.json_1.decodeFromString_jwu9sq_k$(mapper, text));
  };
  function buildSerializer(value, module_0) {
    var tmp;
    if (value instanceof JsonElement) {
      tmp = Companion_getInstance().serializer_9w0wvi_k$();
    } else {
      if (isInterface(value, List)) {
        tmp = ListSerializer(elementSerializer(value, module_0));
      } else {
        if (isArray(value)) {
          var tmp1_safe_receiver = firstOrNull(value);
          var tmp_0;
          if (tmp1_safe_receiver == null) {
            tmp_0 = null;
          } else {
            // Inline function 'kotlin.let' call
            // Inline function 'kotlin.contracts.contract' call
            // Inline function 'io.ktor.client.plugins.kotlinx.serializer.buildSerializer.<anonymous>' call
            tmp_0 = buildSerializer(tmp1_safe_receiver, module_0);
          }
          var tmp2_elvis_lhs = tmp_0;
          tmp = tmp2_elvis_lhs == null ? ListSerializer(serializer_1(StringCompanionObject_getInstance())) : tmp2_elvis_lhs;
        } else {
          if (isInterface(value, Set)) {
            tmp = SetSerializer(elementSerializer(value, module_0));
          } else {
            if (isInterface(value, Map)) {
              var keySerializer = elementSerializer(value.get_keys_wop4xp_k$(), module_0);
              var valueSerializer = elementSerializer(value.get_values_ksazhn_k$(), module_0);
              tmp = MapSerializer(keySerializer, valueSerializer);
            } else {
              var tmp3_elvis_lhs = module_0.getContextual$default_o8kdzb_k$(getKClassFromExpression(value));
              tmp = tmp3_elvis_lhs == null ? serializer_0(getKClassFromExpression(value)) : tmp3_elvis_lhs;
            }
          }
        }
      }
    }
    var tmp_1 = tmp;
    return isInterface(tmp_1, KSerializer) ? tmp_1 : THROW_CCE();
  }
  function elementSerializer(_this__u8e3s4, module_0) {
    // Inline function 'kotlin.collections.distinctBy' call
    // Inline function 'kotlin.collections.map' call
    var this_0 = filterNotNull(_this__u8e3s4);
    // Inline function 'kotlin.collections.mapTo' call
    var destination = ArrayList_init_$Create$(collectionSizeOrDefault(this_0, 10));
    var tmp0_iterator = this_0.iterator_jk1svi_k$();
    while (tmp0_iterator.hasNext_bitz1p_k$()) {
      var item = tmp0_iterator.next_20eer_k$();
      // Inline function 'io.ktor.client.plugins.kotlinx.serializer.elementSerializer.<anonymous>' call
      var tmp$ret$0 = buildSerializer(item, module_0);
      destination.add_utx5q5_k$(tmp$ret$0);
    }
    var set = HashSet_init_$Create$();
    var list = ArrayList_init_$Create$_0();
    var tmp0_iterator_0 = destination.iterator_jk1svi_k$();
    while (tmp0_iterator_0.hasNext_bitz1p_k$()) {
      var e = tmp0_iterator_0.next_20eer_k$();
      // Inline function 'io.ktor.client.plugins.kotlinx.serializer.elementSerializer.<anonymous>' call
      var key = e.get_descriptor_wjt6a0_k$().get_serialName_u2rqhk_k$();
      if (set.add_utx5q5_k$(key)) {
        list.add_utx5q5_k$(e);
      }
    }
    var serializers = list;
    if (serializers.get_size_woubt6_k$() > 1) {
      // Inline function 'kotlin.error' call
      // Inline function 'kotlin.collections.map' call
      // Inline function 'kotlin.collections.mapTo' call
      var destination_0 = ArrayList_init_$Create$(collectionSizeOrDefault(serializers, 10));
      var tmp0_iterator_1 = serializers.iterator_jk1svi_k$();
      while (tmp0_iterator_1.hasNext_bitz1p_k$()) {
        var item_0 = tmp0_iterator_1.next_20eer_k$();
        // Inline function 'io.ktor.client.plugins.kotlinx.serializer.elementSerializer.<anonymous>' call
        var tmp$ret$5 = item_0.get_descriptor_wjt6a0_k$().get_serialName_u2rqhk_k$();
        destination_0.add_utx5q5_k$(tmp$ret$5);
      }
      var message = 'Serializing collections of different element types is not yet supported. ' + ('Selected serializers: ' + destination_0);
      throw IllegalStateException_init_$Create$(toString(message));
    }
    var tmp0_elvis_lhs = singleOrNull(serializers);
    var selected = tmp0_elvis_lhs == null ? serializer_1(StringCompanionObject_getInstance()) : tmp0_elvis_lhs;
    if (selected.get_descriptor_wjt6a0_k$().get_isNullable_67sy7o_k$()) {
      return selected;
    }
    if (!isInterface(selected, KSerializer))
      THROW_CCE();
    var tmp$ret$8;
    $l$block_0: {
      // Inline function 'kotlin.collections.any' call
      var tmp;
      if (isInterface(_this__u8e3s4, Collection)) {
        tmp = _this__u8e3s4.isEmpty_y1axqb_k$();
      } else {
        tmp = false;
      }
      if (tmp) {
        tmp$ret$8 = false;
        break $l$block_0;
      }
      var tmp0_iterator_2 = _this__u8e3s4.iterator_jk1svi_k$();
      while (tmp0_iterator_2.hasNext_bitz1p_k$()) {
        var element = tmp0_iterator_2.next_20eer_k$();
        // Inline function 'io.ktor.client.plugins.kotlinx.serializer.elementSerializer.<anonymous>' call
        if (element == null) {
          tmp$ret$8 = true;
          break $l$block_0;
        }
      }
      tmp$ret$8 = false;
    }
    if (tmp$ret$8) {
      return get_nullable(selected);
    }
    return selected;
  }
  function get_initializer() {
    return initializer;
  }
  var initializer;
  function SerializerInitializer() {
    SerializerInitializer_instance = this;
    // Inline function 'kotlin.collections.plusAssign' call
    var this_0 = get_serializersStore();
    var element = new KotlinxSerializer();
    this_0.add_utx5q5_k$(element);
  }
  var SerializerInitializer_instance;
  function SerializerInitializer_getInstance() {
    if (SerializerInitializer_instance == null)
      new SerializerInitializer();
    return SerializerInitializer_instance;
  }
  //region block: post-declaration
  protoOf(KotlinxSerializer).write_qtfzr3_k$ = write;
  //endregion
  //region block: init
  initializer = SerializerInitializer_getInstance();
  //endregion
  return _;
}(module.exports, require('./kotlin-kotlin-stdlib.js'), require('./kotlinx-serialization-kotlinx-serialization-json.js'), require('./ktor-ktor-http.js'), require('./kotlinx-serialization-kotlinx-serialization-core.js'), require('./ktor-ktor-client-json.js')));

//# sourceMappingURL=ktor-ktor-client-serialization.js.map
