2026-02-24 03:28:13 +05:30
|
|
|
import 'package:real_estate_mobile/features/agents/data/models/agent_type.dart';
|
|
|
|
|
|
|
|
|
|
class AgentProfile {
|
|
|
|
|
final String id;
|
2026-02-24 22:35:16 +05:30
|
|
|
final String? userId;
|
2026-02-24 03:28:13 +05:30
|
|
|
final String firstName;
|
|
|
|
|
final String lastName;
|
2026-02-24 22:35:16 +05:30
|
|
|
final String? headline;
|
2026-02-24 03:28:13 +05:30
|
|
|
final String? bio;
|
|
|
|
|
final String? avatar;
|
2026-02-24 22:35:16 +05:30
|
|
|
final String? companyName;
|
|
|
|
|
final String? phone;
|
|
|
|
|
final String? website;
|
2026-02-24 03:28:13 +05:30
|
|
|
final String? city;
|
|
|
|
|
final String? state;
|
|
|
|
|
final String? country;
|
2026-02-24 22:35:16 +05:30
|
|
|
final double? averageRating;
|
|
|
|
|
final int totalReviews;
|
2026-02-24 03:28:13 +05:30
|
|
|
final bool isVerified;
|
|
|
|
|
final bool isFeatured;
|
2026-02-24 22:35:16 +05:30
|
|
|
final bool isActive;
|
2026-02-24 03:28:13 +05:30
|
|
|
final AgentType? agentType;
|
2026-02-24 22:35:16 +05:30
|
|
|
final AgentUser? user;
|
2026-02-24 03:28:13 +05:30
|
|
|
final List<AgentFieldValue> fieldValues;
|
|
|
|
|
|
|
|
|
|
const AgentProfile({
|
|
|
|
|
required this.id,
|
2026-02-24 22:35:16 +05:30
|
|
|
this.userId,
|
2026-02-24 03:28:13 +05:30
|
|
|
required this.firstName,
|
|
|
|
|
required this.lastName,
|
2026-02-24 22:35:16 +05:30
|
|
|
this.headline,
|
2026-02-24 03:28:13 +05:30
|
|
|
this.bio,
|
|
|
|
|
this.avatar,
|
2026-02-24 22:35:16 +05:30
|
|
|
this.companyName,
|
|
|
|
|
this.phone,
|
|
|
|
|
this.website,
|
2026-02-24 03:28:13 +05:30
|
|
|
this.city,
|
|
|
|
|
this.state,
|
|
|
|
|
this.country,
|
2026-02-24 22:35:16 +05:30
|
|
|
this.averageRating,
|
|
|
|
|
this.totalReviews = 0,
|
2026-02-24 03:28:13 +05:30
|
|
|
this.isVerified = false,
|
|
|
|
|
this.isFeatured = false,
|
2026-02-24 22:35:16 +05:30
|
|
|
this.isActive = true,
|
2026-02-24 03:28:13 +05:30
|
|
|
this.agentType,
|
2026-02-24 22:35:16 +05:30
|
|
|
this.user,
|
2026-02-24 03:28:13 +05:30
|
|
|
this.fieldValues = const [],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
String get fullName => '$firstName $lastName'.trim();
|
|
|
|
|
|
2026-02-24 22:35:16 +05:30
|
|
|
/// Get avatar URL — check agent avatar first, then user avatar
|
|
|
|
|
String? get avatarUrl => avatar ?? user?.avatar;
|
|
|
|
|
|
2026-02-24 03:28:13 +05:30
|
|
|
String get location {
|
|
|
|
|
if (city != null && state != null) return '$city, $state';
|
|
|
|
|
if (city != null) return city!;
|
|
|
|
|
if (state != null) return state!;
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 22:35:16 +05:30
|
|
|
/// Get experience from field values
|
2026-02-24 03:28:13 +05:30
|
|
|
String get experienceText {
|
2026-02-24 22:35:16 +05:30
|
|
|
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 [];
|
2026-02-24 03:28:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
factory AgentProfile.fromJson(Map<String, dynamic> json) {
|
|
|
|
|
return AgentProfile(
|
|
|
|
|
id: json['id'] as String,
|
2026-02-24 22:35:16 +05:30
|
|
|
userId: json['userId'] as String?,
|
2026-02-24 03:28:13 +05:30
|
|
|
firstName: json['firstName'] as String? ?? '',
|
|
|
|
|
lastName: json['lastName'] as String? ?? '',
|
2026-02-24 22:35:16 +05:30
|
|
|
headline: json['headline'] as String?,
|
2026-02-24 03:28:13 +05:30
|
|
|
bio: json['bio'] as String?,
|
|
|
|
|
avatar: json['avatar'] as String?,
|
2026-02-24 22:35:16 +05:30
|
|
|
companyName: json['companyName'] as String?,
|
|
|
|
|
phone: json['phone'] as String?,
|
|
|
|
|
website: json['website'] as String?,
|
2026-02-24 03:28:13 +05:30
|
|
|
city: json['city'] as String?,
|
|
|
|
|
state: json['state'] as String?,
|
|
|
|
|
country: json['country'] as String?,
|
2026-02-24 22:35:16 +05:30
|
|
|
averageRating: (json['averageRating'] as num?)?.toDouble(),
|
|
|
|
|
totalReviews: json['totalReviews'] as int? ?? 0,
|
2026-02-24 03:28:13 +05:30
|
|
|
isVerified: json['isVerified'] as bool? ?? false,
|
|
|
|
|
isFeatured: json['isFeatured'] as bool? ?? false,
|
2026-02-24 22:35:16 +05:30
|
|
|
isActive: json['isActive'] as bool? ?? true,
|
2026-02-24 03:28:13 +05:30
|
|
|
agentType: json['agentType'] != null
|
|
|
|
|
? AgentType.fromJson(json['agentType'] as Map<String, dynamic>)
|
|
|
|
|
: null,
|
2026-02-24 22:35:16 +05:30
|
|
|
user: json['user'] != null
|
|
|
|
|
? AgentUser.fromJson(json['user'] as Map<String, dynamic>)
|
|
|
|
|
: null,
|
2026-02-24 03:28:13 +05:30
|
|
|
fieldValues: (json['fieldValues'] as List<dynamic>?)
|
|
|
|
|
?.map((e) => AgentFieldValue.fromJson(e as Map<String, dynamic>))
|
|
|
|
|
.toList() ??
|
|
|
|
|
const [],
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-02-24 22:35:16 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AgentUser {
|
|
|
|
|
final String id;
|
|
|
|
|
final String email;
|
|
|
|
|
final String? avatar;
|
|
|
|
|
|
|
|
|
|
const AgentUser({
|
|
|
|
|
required this.id,
|
|
|
|
|
required this.email,
|
|
|
|
|
this.avatar,
|
|
|
|
|
});
|
2026-02-24 03:28:13 +05:30
|
|
|
|
2026-02-24 22:35:16 +05:30
|
|
|
factory AgentUser.fromJson(Map<String, dynamic> json) {
|
|
|
|
|
return AgentUser(
|
|
|
|
|
id: json['id'] as String,
|
|
|
|
|
email: json['email'] as String? ?? '',
|
|
|
|
|
avatar: json['avatar'] as String?,
|
|
|
|
|
);
|
2026-02-24 03:28:13 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class AgentFieldValue {
|
|
|
|
|
final String id;
|
2026-02-24 22:35:16 +05:30
|
|
|
final String fieldSlug;
|
|
|
|
|
final String fieldName;
|
|
|
|
|
final String fieldType;
|
2026-02-24 03:28:13 +05:30
|
|
|
final String? textValue;
|
|
|
|
|
final num? numberValue;
|
|
|
|
|
final bool? booleanValue;
|
|
|
|
|
final dynamic jsonValue;
|
|
|
|
|
final String? dateValue;
|
|
|
|
|
|
|
|
|
|
const AgentFieldValue({
|
|
|
|
|
required this.id,
|
2026-02-24 22:35:16 +05:30
|
|
|
required this.fieldSlug,
|
|
|
|
|
required this.fieldName,
|
|
|
|
|
required this.fieldType,
|
2026-02-24 03:28:13 +05:30
|
|
|
this.textValue,
|
|
|
|
|
this.numberValue,
|
|
|
|
|
this.booleanValue,
|
|
|
|
|
this.jsonValue,
|
|
|
|
|
this.dateValue,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
factory AgentFieldValue.fromJson(Map<String, dynamic> json) {
|
|
|
|
|
return AgentFieldValue(
|
2026-02-24 22:35:16 +05:30
|
|
|
id: json['id'] as String? ?? '',
|
|
|
|
|
fieldSlug: json['fieldSlug'] as String? ?? '',
|
|
|
|
|
fieldName: json['fieldName'] as String? ?? '',
|
|
|
|
|
fieldType: json['fieldType'] as String? ?? '',
|
2026-02-24 03:28:13 +05:30
|
|
|
textValue: json['textValue'] as String?,
|
|
|
|
|
numberValue: json['numberValue'] as num?,
|
|
|
|
|
booleanValue: json['booleanValue'] as bool?,
|
|
|
|
|
jsonValue: json['jsonValue'],
|
|
|
|
|
dateValue: json['dateValue'] as String?,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|