getEntityClass method

String getEntityClass(
  1. String suffix,
  2. String name,
  3. String parent,
  4. Map? map, [
  5. bool root = false,
])

Implementation

String getEntityClass(String suffix, String name, String parent, Map? map,
    [bool root = false]) {
  if (map == null) return '';
  final apiClassName = ModelClassNameHelper.getClassName(
      listClassNameEntity, suffix, name, root, true, parent);
  final classString = '''class $apiClassName extends Equatable {
${setConstractor(apiClassName, map)}

${setTypeData(map, suffix, listClassNameEntity, apiClassName)}

$apiClassName copyWith({
  ${map.keys.map((e) => '${getTypeVariable(e, map[e], suffix, listClassNameEntity, apiClassName)}? ${e.toString().camelCase},').join('\n    ')}
}) {
  return $apiClassName(
    ${map.keys.map((e) => '${e.toString().camelCase}: ${e.toString().camelCase} ?? this.${e.toString().camelCase},').join('\n      ')}
  );
}

${setPropsEquatable(map)}
}

${map.keys.map((e) => map[e] is Map ? getEntityClass(suffix, e.toString().pascalCase, apiClassName, map[e]) : '').join()}
${map.keys.map((e) => map[e] is List ? map[e] == null ? '' : (map[e] as List).isEmpty ? '' : (map[e] as List).first is! Map ? '' : getEntityClass(suffix, e.toString().pascalCase, apiClassName, (map[e] as List).first) : '').join()}
''';

  return classString;
}