import 'package:mobilki_lab1/data/dtos/pokemon_dto.dart'; import 'package:mobilki_lab1/domain/models/card.dart'; import 'package:mobilki_lab1/domain/models/home.dart'; const _imagePlaceholder = 'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png'; extension PokemonDtoToModel on PokemonDto { HomeData toDomain() => HomeData( data: [toCardData()], nextPage: null, ); CardData toCardData() => CardData( name ?? 'UNKNOWN', descriptionText: _makeDescriptionText(types, abilities), imageUrl: sprites?.front_default ?? _imagePlaceholder, ); String _makeDescriptionText(List? types, List? abilities) { final typeNames = types?.map((e) => e.type?.name).whereType().join(', ') ?? ''; final abilityNames = abilities?.map((e) => e.ability?.name).whereType().join(', ') ?? ''; return 'Types: $typeNames\nAbilities: $abilityNames'; } }