class {{{classname}}} {
{{>dart_constructor}}

  {{#vars}}
  {{#description}}
  /// {{{.}}}
  {{/description}}
  {{^isEnum}}
    {{#minimum}}
  // minimum: {{{.}}}
    {{/minimum}}
    {{#maximum}}
  // maximum: {{{.}}}
    {{/maximum}}
  {{/isEnum}}
  {{{datatypeWithEnum}}} {{{name}}};

  {{/vars}}
  @override
  bool operator ==(Object other) => identical(this, other) || other is {{{classname}}} &&
  {{#vars}}
     other.{{{name}}} == {{{name}}}{{^-last}} &&{{/-last}}{{#-last}};{{/-last}}
  {{/vars}}

  @override
  int get hashCode =>
  {{#vars}}
    ({{{name}}} == null ? 0 : {{{name}}}.hashCode){{^-last}} +{{/-last}}{{#-last}};{{/-last}}
  {{/vars}}

  @override
  String toString() => '{{{classname}}}[{{#vars}}{{{name}}}=${{{name}}}{{^-last}}, {{/-last}}{{/vars}}]';

  Map<String, dynamic> toJson() {
    final json = <String, dynamic>{};
  {{#vars}}
    {{^required}}
    if ({{{name}}} != null) {
    {{/required}}
    {{#isDateTime}}
      {{#pattern}}
      json[r'{{{baseName}}}'] = {{#required}}{{#isNullable}}{{{name}}} == null ? null : {{/isNullable}}{{/required}}_dateEpochMarker == '{{{pattern}}}'
        ? {{{name}}}.millisecondsSinceEpoch
        : {{{name}}}.toUtc().toIso8601String();
      {{/pattern}}
      {{^pattern}}
      json[r'{{{baseName}}}'] = {{#required}}{{#isNullable}}{{{name}}} == null ? null : {{/isNullable}}{{/required}}{{{name}}}.toUtc().toIso8601String();
      {{/pattern}}
    {{/isDateTime}}
    {{#isDate}}
      {{#pattern}}
      json[r'{{{baseName}}}'] = {{#required}}{{#isNullable}}{{{name}}} == null ? null : {{/isNullable}}{{/required}}_dateEpochMarker == '{{{pattern}}}'
        ? {{{name}}}.millisecondsSinceEpoch
        : _dateFormatter.format({{{name}}}.toUtc());
      {{/pattern}}
      {{^pattern}}
      json[r'{{{baseName}}}'] = {{#required}}{{#isNullable}}{{{name}}} == null ? null : {{/isNullable}}{{/required}}_dateFormatter.format({{{name}}}.toUtc());
      {{/pattern}}
    {{/isDate}}
    {{^isDateTime}}
      {{^isDate}}
      json[r'{{{baseName}}}'] = {{#required}}{{#isNullable}}{{{name}}} == null ? null : {{/isNullable}}{{/required}}{{{name}}};
      {{/isDate}}
    {{/isDateTime}}
    {{^required}}
    }
    {{/required}}
  {{/vars}}
    return json;
  }

  /// Returns a new [{{{classname}}}] instance and imports its values from
  /// [json] if it's non-null, null if [json] is null.
  static {{{classname}}} fromJson(Map<String, dynamic> json) => json == null
    ? null
    : {{{classname}}}(
  {{#vars}}
  {{#isDateTime}}
        {{{name}}}: json[r'{{{baseName}}}'] == null
          ? null
    {{#pattern}}
          : _dateEpochMarker == '{{{pattern}}}'
            ? DateTime.fromMillisecondsSinceEpoch(json[r'{{{baseName}}}'] as int, isUtc: true)
            : DateTime.parse(json[r'{{{baseName}}}']),
    {{/pattern}}
    {{^pattern}}
          : DateTime.parse(json[r'{{{baseName}}}']),
    {{/pattern}}
  {{/isDateTime}}
  {{#isDate}}
        {{{name}}}: json[r'{{{baseName}}}'] == null
          ? null
    {{#pattern}}
          : _dateEpochMarker == '{{{pattern}}}'
            ? DateTime.fromMillisecondsSinceEpoch(json[r'{{{baseName}}}'] as int, isUtc: true)
            : DateTime.parse(json[r'{{{baseName}}}']),
    {{/pattern}}
    {{^pattern}}
          : DateTime.parse(json[r'{{{baseName}}}']),
    {{/pattern}}
  {{/isDate}}
  {{^isDateTime}}
  {{^isDate}}
    {{#complexType}}
      {{#isArray}}
        {{#items.isArray}}
        {{{name}}}: json[r'{{{baseName}}}'] == null
          ? null
          : (json[r'{{{baseName}}}'] as List).map(
      {{#items.complexType}}
              {{items.complexType}}.listFromJson(json[r'{{{baseName}}}'])
      {{/items.complexType}}
      {{^items.complexType}}
              (e) => e == null ? null : (e as List).cast<{{items.items.dataType}}>()
      {{/items.complexType}}
            ).toList(growable: false),
        {{/items.isArray}}
        {{^items.isArray}}
        {{{name}}}: {{{complexType}}}.listFromJson(json[r'{{{baseName}}}']),
        {{/items.isArray}}
      {{/isArray}}
      {{^isArray}}
        {{#isMap}}
          {{#items.isArray}}
        {{{name}}}: json[r'{{{baseName}}}'] == null
          ? null
              {{#items.complexType}}
          : {{items.complexType}}.mapListFromJson(json[r'{{{baseName}}}']),
              {{/items.complexType}}
              {{^items.complexType}}
          : (json[r'{{{baseName}}}'] as Map).cast<String, List>(),
              {{/items.complexType}}
          {{/items.isArray}}
          {{^items.isArray}}
              {{#items.isMap}}
        {{{name}}}: json[r'{{{baseName}}}'] == null
          ? null
            {{#items.complexType}}
          : {{items.complexType}}.mapFromJson(json[r'{{{baseName}}}']),
            {{/items.complexType}}
            {{^items.complexType}}
          : (json[r'{{{baseName}}}'] as Map).cast<String, Map>(),
            {{/items.complexType}}
          {{/items.isMap}}
          {{^items.isMap}}
            {{{name}}}: json[r'{{{baseName}}}']
          {{/items.isMap}}
          {{/items.isArray}}
        {{/isMap}}
        {{^isMap}}
            {{#isBinary}}
        {{{name}}}: null, // No support for decoding binary content from JSON
            {{/isBinary}}
            {{^isBinary}}
        {{{name}}}: {{{complexType}}}.fromJson(json[r'{{{baseName}}}']),
            {{/isBinary}}
        {{/isMap}}
      {{/isArray}}
    {{/complexType}}
    {{^complexType}}
      {{#isArray}}
        {{#isEnum}}
        {{{name}}}: {{{items.datatypeWithEnum}}}.listFromJson(json[r'{{{baseName}}}']),
        {{/isEnum}}
        {{^isEnum}}
        {{{name}}}: json[r'{{{baseName}}}'] == null
          ? null
          : (json[r'{{{baseName}}}'] as {{#uniqueItems}}Set{{/uniqueItems}}{{^uniqueItems}}List{{/uniqueItems}}).cast<{{{items.datatype}}}>(),
        {{/isEnum}}
      {{/isArray}}
      {{^isArray}}
        {{#isMap}}
        {{{name}}}: json[r'{{{baseName}}}'] == null ?
          null :
          (json[r'{{{baseName}}}'] as Map).cast<String, {{{items.datatype}}}>(),
        {{/isMap}}
        {{^isMap}}
          {{#isNumber}}
        {{{name}}}: json[r'{{{baseName}}}'] == null ?
          null :
          json[r'{{{baseName}}}'].toDouble(),
          {{/isNumber}}
          {{^isNumber}}
    {{^isEnum}}
        {{{name}}}: json[r'{{{baseName}}}'],
    {{/isEnum}}
    {{#isEnum}}
        {{{name}}}: {{{enumName}}}.fromJson(json[r'{{{baseName}}}']),
    {{/isEnum}}
          {{/isNumber}}
        {{/isMap}}
      {{/isArray}}
    {{/complexType}}
  {{/isDate}}
  {{/isDateTime}}
  {{/vars}}
    );

  static List<{{{classname}}}> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
    json == null || json.isEmpty
      ? true == emptyIsNull ? null : <{{{classname}}}>[]
      : json.map((dynamic value) => {{{classname}}}.fromJson(value)).toList(growable: true == growable);

  static Map<String, {{{classname}}}> mapFromJson(Map<String, dynamic> json) {
    final map = <String, {{{classname}}}>{};
    if (json?.isNotEmpty == true) {
      json.forEach((key, value) => map[key] = {{{classname}}}.fromJson(value));
    }
    return map;
  }

  // maps a json object with a list of {{{classname}}}-objects as value to a dart map
  static Map<String, List<{{{classname}}}>> mapListFromJson(Map<String, dynamic> json, {bool emptyIsNull, bool growable,}) {
    final map = <String, List<{{{classname}}}>>{};
    if (json?.isNotEmpty == true) {
      json.forEach((key, value) {
        map[key] = {{{classname}}}.listFromJson(value, emptyIsNull: emptyIsNull, growable: growable,);
      });
    }
    return map;
  }
}
{{#vars}}
    {{#isEnum}}
        {{^isContainer}}

{{>serialization/native/native_enum_inline}}
        {{/isContainer}}
        {{#isContainer}}
            {{#mostInnerItems}}

{{>serialization/native/native_enum_inline}}
            {{/mostInnerItems}}
        {{/isContainer}}
    {{/isEnum}}
{{/vars}}