2024-12-20 14:50:19 +04:00
|
|
|
import 'package:pmd_lab/data/dtos/titans_dto.dart';
|
2024-11-27 23:10:56 +04:00
|
|
|
import 'package:pmd_lab/domain/models/card.dart';
|
2024-12-20 20:49:02 +04:00
|
|
|
import 'package:pmd_lab/domain/models/home.dart';
|
2024-11-27 23:10:56 +04:00
|
|
|
|
|
|
|
const _imagePlaceholder = 'https://cdn-icons-png.flaticon.com/512/4054/4054617.png';
|
|
|
|
|
2024-12-20 20:49:02 +04:00
|
|
|
extension TitansDtoToModel on TitansDto {
|
|
|
|
HomeData toDomain() => HomeData(
|
|
|
|
data: results?.map((e) => e.toDomain()).toList(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
extension TitanResultsDtoToModel on TitansResultsDto {
|
2024-11-27 23:10:56 +04:00
|
|
|
CardData toDomain() => CardData(
|
2024-12-20 16:09:01 +04:00
|
|
|
name ?? 'UNKNOWN',
|
2024-12-20 18:13:20 +04:00
|
|
|
img: img ?? _imagePlaceholder,
|
2024-12-20 16:09:01 +04:00
|
|
|
description: _makeDescription(height, abilities, allegiance),
|
2024-12-20 18:13:20 +04:00
|
|
|
id: id.toString(),
|
2024-12-17 14:33:28 +04:00
|
|
|
);
|
2024-12-20 16:09:01 +04:00
|
|
|
String _makeDescription(String? height, List<String>? abilities, String? allegiance) {
|
|
|
|
List<String> descriptionParts = [];
|
|
|
|
if (height != null && height.isNotEmpty) {
|
|
|
|
descriptionParts.add('Height: $height');
|
|
|
|
}
|
|
|
|
if (allegiance != null && allegiance.isNotEmpty) {
|
|
|
|
descriptionParts.add('Allegiance: $allegiance');
|
|
|
|
}
|
|
|
|
if (abilities != null && abilities.isNotEmpty) {
|
|
|
|
final abilitiesStr = abilities.join(', ');
|
|
|
|
descriptionParts.add('Abilities: $abilitiesStr.');
|
|
|
|
}
|
2024-12-20 18:13:20 +04:00
|
|
|
return descriptionParts.join('\n');
|
2024-11-27 23:10:56 +04:00
|
|
|
}
|
2024-12-17 11:50:32 +04:00
|
|
|
}
|