import 'package:flutter_android_app/components/locale/l10n/app_localizations.dart'; import 'package:flutter_android_app/data/dtos/coins_dto.dart'; import 'package:flutter_android_app/domain/models/card.dart'; import 'package:flutter_android_app/domain/models/home.dart'; extension CoinDataDtoToModel on CoinDataDto { CardData toDomain(AppLocale? locale) => CardData( id: id ?? 'UNKNOWN', title: name ?? 'UNKNOWN', imageUrl: image, currentPrice: _getLocalizedPrice(currentPrice, locale?.localeName), priceChange: _getLocalizedPriceChange(priceChange24h, locale), ); String _getLocalizedPrice(double? price, String? localeName) { if (localeName == null) { return '$price \$'; } return switch (localeName) { 'ru' => '$price ₽', _ => '$price \$', }; } String _getLocalizedPriceChange(double? priceChange, AppLocale? locale) { if (priceChange == null) { return '+${_getLocalizedPrice(0, locale?.localeName)}'; } String retVal = ''; if (priceChange >= 0.0) { retVal += '+'; } retVal += _getLocalizedPrice(priceChange, locale?.localeName); return '$retVal ${locale?.coinDataPriceChange}'; } } extension CoinsDtoToModel on CoinsDto { HomeData toDomain(AppLocale? locale, int currentPage) => HomeData( data: coins?.map((e) => e.toDomain(locale)).toList(), nextPage: currentPage + 1, ); }