Files
mobile-app/lib/features/agents/data/models/agent_profile.dart

166 lines
4.7 KiB
Dart

import 'package:real_estate_mobile/features/agents/data/models/agent_type.dart';
class AgentProfile {
final String id;
final String firstName;
final String lastName;
final String slug;
final String? email;
final String? phone;
final String? bio;
final String? avatar;
final String? licenseNumber;
final int? experience;
final List<String> specializations;
final List<String> languages;
final List<String> serviceAreas;
final String? city;
final String? state;
final String? country;
final double? rating;
final int reviewCount;
final bool isVerified;
final bool isFeatured;
final bool isAvailable;
final String? agentTypeId;
final AgentType? agentType;
final List<AgentFieldValue> fieldValues;
const AgentProfile({
required this.id,
required this.firstName,
required this.lastName,
required this.slug,
this.email,
this.phone,
this.bio,
this.avatar,
this.licenseNumber,
this.experience,
this.specializations = const [],
this.languages = const [],
this.serviceAreas = const [],
this.city,
this.state,
this.country,
this.rating,
this.reviewCount = 0,
this.isVerified = false,
this.isFeatured = false,
this.isAvailable = false,
this.agentTypeId,
this.agentType,
this.fieldValues = const [],
});
String get fullName => '$firstName $lastName'.trim();
String get location {
if (city != null && state != null) return '$city, $state';
if (city != null) return city!;
if (state != null) return state!;
if (serviceAreas.isNotEmpty) return serviceAreas.first;
return '';
}
String get experienceText {
if (experience == null) return '';
return '$experience+ years in the real estate industry.';
}
factory AgentProfile.fromJson(Map<String, dynamic> json) {
return AgentProfile(
id: json['id'] as String,
firstName: json['firstName'] as String? ?? '',
lastName: json['lastName'] as String? ?? '',
slug: json['slug'] as String? ?? '',
email: json['email'] as String?,
phone: json['phone'] as String?,
bio: json['bio'] as String?,
avatar: json['avatar'] as String?,
licenseNumber: json['licenseNumber'] as String?,
experience: json['experience'] as int?,
specializations: _parseStringList(json['specializations']),
languages: _parseStringList(json['languages']),
serviceAreas: _parseStringList(json['serviceAreas']),
city: json['city'] as String?,
state: json['state'] as String?,
country: json['country'] as String?,
rating: (json['rating'] as num?)?.toDouble(),
reviewCount: json['reviewCount'] as int? ?? 0,
isVerified: json['isVerified'] as bool? ?? false,
isFeatured: json['isFeatured'] as bool? ?? false,
isAvailable: json['isAvailable'] as bool? ?? false,
agentTypeId: json['agentTypeId'] as String?,
agentType: json['agentType'] != null
? AgentType.fromJson(json['agentType'] as Map<String, dynamic>)
: null,
fieldValues: (json['fieldValues'] as List<dynamic>?)
?.map((e) => AgentFieldValue.fromJson(e as Map<String, dynamic>))
.toList() ??
const [],
);
}
static List<String> _parseStringList(dynamic value) {
if (value == null) return const [];
if (value is List) return value.map((e) => e.toString()).toList();
return const [];
}
}
class AgentFieldValue {
final String id;
final String fieldId;
final String? textValue;
final num? numberValue;
final bool? booleanValue;
final dynamic jsonValue;
final String? dateValue;
final AgentField field;
const AgentFieldValue({
required this.id,
required this.fieldId,
this.textValue,
this.numberValue,
this.booleanValue,
this.jsonValue,
this.dateValue,
required this.field,
});
factory AgentFieldValue.fromJson(Map<String, dynamic> json) {
return AgentFieldValue(
id: json['id'] as String,
fieldId: json['fieldId'] as String,
textValue: json['textValue'] as String?,
numberValue: json['numberValue'] as num?,
booleanValue: json['booleanValue'] as bool?,
jsonValue: json['jsonValue'],
dateValue: json['dateValue'] as String?,
field: AgentField.fromJson(json['field'] as Map<String, dynamic>),
);
}
}
class AgentField {
final String slug;
final String name;
final String fieldType;
const AgentField({
required this.slug,
required this.name,
required this.fieldType,
});
factory AgentField.fromJson(Map<String, dynamic> json) {
return AgentField(
slug: json['slug'] as String,
name: json['name'] as String,
fieldType: json['fieldType'] as String,
);
}
}