---
source: src/tests/snapshots/mod.rs
expression: generated
---
// some comment
import "package:equatable/equatable.dart";

final class Foo with EquatableMixin {
  final String name;
  final int age;
  final Bar bar;

  const Foo({this.name = "hello", required this.age = 123, required this.bar});

  @override
  List<Object?> get props => [name, age, bar];

  FooBuilder toBuilder() =>
      FooBuilder(name: name, age: age, bar: bar.toBuilder());

  Map<String, dynamic> toJson() => {
    "name": name,
    "age": age,
    "bar": bar.toJson(),
  };
  factory Foo.fromJson(Map<String, dynamic> json) => Foo(
    name: json["name"] as String,
    age: json["age"] as int,
    bar: Bar.fromJson(json["bar"] as Map<String, dynamic>),
  );
}

final class FooBuilder {
  String name;
  int age;
  BarBuilder bar;

  FooBuilder({required this.name, required this.age, required this.bar});

  Foo build() => Foo(name: name, age: age, bar: bar.build());
}

final class Bar with EquatableMixin {
  final String x;
  final String y;

  const Bar({required this.x, required this.y});

  @override
  List<Object?> get props => [x, y];

  BarBuilder toBuilder() => BarBuilder(x: x, y: y);

  Map<String, dynamic> toJson() => {"x": x, "y": y};
  factory Bar.fromJson(Map<String, dynamic> json) =>
      Bar(x: json["x"] as String, y: json["y"] as String);
}

final class BarBuilder {
  String x;
  String y;

  BarBuilder({required this.x, required this.y});

  Bar build() => Bar(x: x, y: y);
}

abstract final class Animal {
  const Animal();

  Map<String, dynamic> toJson();
  factory Animal.fromJson(Map<String, dynamic> json) => switch (json["type"]) {
    "Dog" => Dog.fromJson(json),
    "Cat" => Cat.fromJson(json),
    final other => throw ArgumentError("unknown discrimminant: $other"),
  };
}

final class Dog extends Animal with EquatableMixin {
  final String name;

  const Dog({required this.name}) : super();

  @override
  List<Object?> get props => [name];

  DogBuilder toBuilder() => DogBuilder(name: name);

  @override
  Map<String, dynamic> toJson() => {"name": name, "type": "Dog"};
  factory Dog.fromJson(Map<String, dynamic> json) =>
      Dog(name: json["name"] as String);
}

final class DogBuilder {
  String name;

  DogBuilder({required this.name});

  Dog build() => Dog(name: name);
}

final class Cat extends Animal with EquatableMixin {
  final int age;

  const Cat({required this.age}) : super();

  @override
  List<Object?> get props => [age];

  CatBuilder toBuilder() => CatBuilder(age: age);

  @override
  Map<String, dynamic> toJson() => {"age": age, "type": "Cat"};
  factory Cat.fromJson(Map<String, dynamic> json) =>
      Cat(age: json["age"] as int);
}

final class CatBuilder {
  int age;

  CatBuilder({required this.age});

  Cat build() => Cat(age: age);
}
