import 'package:test_app/data/dto/characters_dto.dart'; import 'package:test_app/domain/card.dart'; import 'package:test_app/domain/home.dart'; const _imagePlaceholder = 'https://www.bellcold.com/wp-content/uploads/2024/04/Person-Placeholder-Icon.jpeg'; extension CharactersDtoToModel on CharactersDto { HomeData toDomain() => HomeData( data: data?.map((e) => e.toDomain()).toList(), currentPage: meta?.pagination?.current, nextPage: meta?.pagination?.next, ); } extension CharacterDtoToModel on CharacterDto { CardData toDomain() => CardData( attributes?.name ?? 'UNKNOWN', imageUrl: attributes?.image ?? _imagePlaceholder, descriptionText: _makeDescriptionText(attributes?.born, attributes?.died), ); } String _makeDescriptionText(String? born, String? died) { if (born != null && died != null) { return '$born - $died'; } if (born != null) { return 'born: $born'; } if (died != null) { return 'died: $died'; } return ''; }