108 lines
2.7 KiB
Dart
108 lines
2.7 KiB
Dart
import 'package:autos/domain/entities/brands.dart';
|
|
|
|
class Brand {
|
|
final String id;
|
|
final String name;
|
|
final String logo;
|
|
final bool dropship;
|
|
final List<PriceGroup> pricegroups;
|
|
|
|
Brand({
|
|
required this.id,
|
|
required this.name,
|
|
required this.logo,
|
|
required this.dropship,
|
|
required this.pricegroups,
|
|
});
|
|
|
|
factory Brand.fromJson(Map<String, dynamic> json) {
|
|
return Brand(
|
|
id: json['id'].toString(),
|
|
name: json['name'] ?? '',
|
|
logo: json['logo'] ?? '',
|
|
dropship: json['dropship'] ?? false,
|
|
pricegroups: (json['pricegroups'] as List<dynamic>?)
|
|
?.map((e) => PriceGroup.fromJson(e))
|
|
.toList() ??
|
|
[],
|
|
);
|
|
}
|
|
|
|
/// 🔥 Model → Entity
|
|
BrandEntity toEntity() {
|
|
return BrandEntity(
|
|
id: id,
|
|
name: name,
|
|
logo: logo,
|
|
dropship: dropship,
|
|
pricegroups: pricegroups.map((e) => e.toEntity()).toList(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class PriceGroup {
|
|
final String pricegroupId;
|
|
final String pricegroupName;
|
|
final String pricegroupPrefix;
|
|
final List<dynamic> locationRules;
|
|
final List<PurchaseRestriction> purchaseRestrictions;
|
|
|
|
PriceGroup({
|
|
required this.pricegroupId,
|
|
required this.pricegroupName,
|
|
required this.pricegroupPrefix,
|
|
required this.locationRules,
|
|
required this.purchaseRestrictions,
|
|
});
|
|
|
|
factory PriceGroup.fromJson(Map<String, dynamic> json) {
|
|
return PriceGroup(
|
|
pricegroupId: json['pricegroup_id'].toString(),
|
|
pricegroupName: json['pricegroup_name'] ?? '',
|
|
pricegroupPrefix: json['pricegroup_prefix'] ?? '',
|
|
locationRules: json['location_rules'] ?? [],
|
|
purchaseRestrictions: (json['purchase_restrictions'] as List<dynamic>?)
|
|
?.map((e) => PurchaseRestriction.fromJson(e))
|
|
.toList() ??
|
|
[],
|
|
);
|
|
}
|
|
|
|
/// 🔥 Model → Entity
|
|
PriceGroupEntity toEntity() {
|
|
return PriceGroupEntity(
|
|
pricegroupId: pricegroupId,
|
|
pricegroupName: pricegroupName,
|
|
pricegroupPrefix: pricegroupPrefix,
|
|
locationRules: locationRules,
|
|
purchaseRestrictions:
|
|
purchaseRestrictions.map((e) => e.toEntity()).toList(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class PurchaseRestriction {
|
|
final String program;
|
|
final String yourStatus;
|
|
|
|
PurchaseRestriction({
|
|
required this.program,
|
|
required this.yourStatus,
|
|
});
|
|
|
|
factory PurchaseRestriction.fromJson(Map<String, dynamic> json) {
|
|
return PurchaseRestriction(
|
|
program: json['program'] ?? '',
|
|
yourStatus: json['your_status'] ?? '',
|
|
);
|
|
}
|
|
|
|
/// 🔥 Model → Entity
|
|
PurchaseRestrictionEntity toEntity() {
|
|
return PurchaseRestrictionEntity(
|
|
program: program,
|
|
yourStatus: yourStatus,
|
|
);
|
|
}
|
|
}
|