Files
tripz-llc/apps/rider/lib/features/home/data/models/place_model.dart
T

72 lines
2.1 KiB
Dart

import 'package:equatable/equatable.dart';
import 'gate_model.dart';
/// نموذج مكان من نتائج بحث انطلق (geocode / search).
class PlaceModel extends Equatable {
final String? placeId;
final String name;
final String? address;
final double lat;
final double lng;
final String? category;
final double? totalScore;
final String? source;
final List<Gate> gates;
const PlaceModel({
this.placeId,
required this.name,
this.address,
required this.lat,
required this.lng,
this.category,
this.totalScore,
this.source,
this.gates = const [],
});
/// استجابة انطلق الحقيقية — الحقول الم标准.
factory PlaceModel.fromJson(Map<String, dynamic> j) {
final lat = (j['latitude'] ?? j['location']?['lat'] ?? 0) as num;
final lng = (j['longitude'] ?? j['location']?['lng'] ?? 0) as num;
return PlaceModel(
placeId: j['id'] as String?,
name: (j['name'] ?? '') as String,
address: (j['full_address'] ?? j['address']) as String?,
lat: lat.toDouble(),
lng: lng.toDouble(),
category: j['category'] as String?,
totalScore: (j['totalScore'] as num?)?.toDouble(),
source: j['source'] as String?,
gates: (j['gates'] as List?)
?.map((g) => Gate.fromJson(g as Map<String, dynamic>))
.toList() ??
const [],
);
}
Map<String, dynamic> toJson() => {
if (placeId != null) 'id': placeId,
'name': name,
if (address != null) 'full_address': address,
'latitude': lat,
'longitude': lng,
if (category != null) 'category': category,
if (totalScore != null) 'totalScore': totalScore,
if (source != null) 'source': source,
};
/// هل لهذا المكان أبواب متعددة?
bool get hasMultipleGates => gates.length > 1;
/// الباب الرئيسي إن وُجد.
Gate? get mainGate => gates.cast<Gate?>().firstWhere(
(g) => g!.isMainGate,
orElse: () => null,
);
@override
List<Object?> get props =>
[placeId, name, address, lat, lng, category, totalScore, source, gates];
}