Files
mobile-app/lib/features/agents/data/models/agent_profile.dart
2026-02-24 22:35:16 +05:30

185 lines
5.2 KiB
Dart

import 'package:real_estate_mobile/features/agents/data/models/agent_type.dart';
class AgentProfile {
final String id;
final String? userId;
final String firstName;
final String lastName;
final String? headline;
final String? bio;
final String? avatar;
final String? companyName;
final String? phone;
final String? website;
final String? city;
final String? state;
final String? country;
final double? averageRating;
final int totalReviews;
final bool isVerified;
final bool isFeatured;
final bool isActive;
final AgentType? agentType;
final AgentUser? user;
final List<AgentFieldValue> fieldValues;
const AgentProfile({
required this.id,
this.userId,
required this.firstName,
required this.lastName,
this.headline,
this.bio,
this.avatar,
this.companyName,
this.phone,
this.website,
this.city,
this.state,
this.country,
this.averageRating,
this.totalReviews = 0,
this.isVerified = false,
this.isFeatured = false,
this.isActive = true,
this.agentType,
this.user,
this.fieldValues = const [],
});
String get fullName => '$firstName $lastName'.trim();
/// Get avatar URL — check agent avatar first, then user avatar
String? get avatarUrl => avatar ?? user?.avatar;
String get location {
if (city != null && state != null) return '$city, $state';
if (city != null) return city!;
if (state != null) return state!;
return '';
}
/// Get experience from field values
String get experienceText {
for (final fv in fieldValues) {
if (fv.fieldSlug.contains('experience') ||
fv.fieldName.toLowerCase().contains('experience')) {
if (fv.textValue != null) return fv.textValue!;
if (fv.numberValue != null) {
return '${fv.numberValue!.toInt()}+ years in the real estate industry.';
}
}
}
return '';
}
/// Get specializations from field values
List<String> get specializations {
for (final fv in fieldValues) {
final slug = fv.fieldSlug.toLowerCase();
if (slug.contains('specialization') ||
slug.contains('property_type') ||
slug.contains('loan_type')) {
if (fv.jsonValue is List) {
return (fv.jsonValue as List).map((e) => e.toString()).toList();
}
if (fv.textValue != null) {
return fv.textValue!.split(',').map((s) => s.trim()).toList();
}
}
}
return [];
}
factory AgentProfile.fromJson(Map<String, dynamic> json) {
return AgentProfile(
id: json['id'] as String,
userId: json['userId'] as String?,
firstName: json['firstName'] as String? ?? '',
lastName: json['lastName'] as String? ?? '',
headline: json['headline'] as String?,
bio: json['bio'] as String?,
avatar: json['avatar'] as String?,
companyName: json['companyName'] as String?,
phone: json['phone'] as String?,
website: json['website'] as String?,
city: json['city'] as String?,
state: json['state'] as String?,
country: json['country'] as String?,
averageRating: (json['averageRating'] as num?)?.toDouble(),
totalReviews: json['totalReviews'] as int? ?? 0,
isVerified: json['isVerified'] as bool? ?? false,
isFeatured: json['isFeatured'] as bool? ?? false,
isActive: json['isActive'] as bool? ?? true,
agentType: json['agentType'] != null
? AgentType.fromJson(json['agentType'] as Map<String, dynamic>)
: null,
user: json['user'] != null
? AgentUser.fromJson(json['user'] as Map<String, dynamic>)
: null,
fieldValues: (json['fieldValues'] as List<dynamic>?)
?.map((e) => AgentFieldValue.fromJson(e as Map<String, dynamic>))
.toList() ??
const [],
);
}
}
class AgentUser {
final String id;
final String email;
final String? avatar;
const AgentUser({
required this.id,
required this.email,
this.avatar,
});
factory AgentUser.fromJson(Map<String, dynamic> json) {
return AgentUser(
id: json['id'] as String,
email: json['email'] as String? ?? '',
avatar: json['avatar'] as String?,
);
}
}
class AgentFieldValue {
final String id;
final String fieldSlug;
final String fieldName;
final String fieldType;
final String? textValue;
final num? numberValue;
final bool? booleanValue;
final dynamic jsonValue;
final String? dateValue;
const AgentFieldValue({
required this.id,
required this.fieldSlug,
required this.fieldName,
required this.fieldType,
this.textValue,
this.numberValue,
this.booleanValue,
this.jsonValue,
this.dateValue,
});
factory AgentFieldValue.fromJson(Map<String, dynamic> json) {
return AgentFieldValue(
id: json['id'] as String? ?? '',
fieldSlug: json['fieldSlug'] as String? ?? '',
fieldName: json['fieldName'] as String? ?? '',
fieldType: json['fieldType'] 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?,
);
}
}