2026-07-08 13:32:04 +02:00
|
|
|
/// Kapcsolat (névjegy) — a Supabase `contacts` táblát tükrözi.
|
|
|
|
|
///
|
|
|
|
|
/// Ez a menü CSAK online, bejelentkezett és jogosult felhasználóknak
|
|
|
|
|
/// érhető el, ezért nincs lokális tükrözés/offline-sync: közvetlenül a
|
|
|
|
|
/// Supabase-ből olvassuk/írjuk, a hozzáférést az RLS + a jogosultság-
|
|
|
|
|
/// tábla dönti el. Az uuid szerveroldali (gen_random_uuid()).
|
|
|
|
|
class Contact {
|
|
|
|
|
final String? id; // uuid — új rekordnál null, a szerver adja
|
2026-07-08 22:13:30 +02:00
|
|
|
final String
|
|
|
|
|
projectId; // az AKTUÁLIS projekt uuid-ja (terepi_seged_projects.id)
|
2026-07-08 13:32:04 +02:00
|
|
|
final String name;
|
|
|
|
|
final String address;
|
|
|
|
|
final String phone;
|
|
|
|
|
final String email;
|
|
|
|
|
final String note;
|
|
|
|
|
final String? createdBy;
|
2026-08-06 16:14:30 +02:00
|
|
|
|
2026-07-08 13:32:04 +02:00
|
|
|
final DateTime? updatedAt;
|
|
|
|
|
|
2026-08-06 16:14:30 +02:00
|
|
|
/// Opcionális helyszín — WGS84 (lat/lon) és EOV (eovY/eovX) is tárolva,
|
|
|
|
|
/// akárcsak a többi geometria-típusnál. Csak akkor van kitöltve, ha a
|
|
|
|
|
/// térképi "Kapcsolat" eszközzel vették fel, vagy utólag hozzárendelték.
|
|
|
|
|
final double? lat;
|
|
|
|
|
final double? lon;
|
|
|
|
|
final double? eovY;
|
|
|
|
|
final double? eovX;
|
|
|
|
|
|
2026-07-08 13:32:04 +02:00
|
|
|
const Contact({
|
|
|
|
|
this.id,
|
2026-07-08 22:13:30 +02:00
|
|
|
required this.projectId,
|
2026-07-08 13:32:04 +02:00
|
|
|
required this.name,
|
|
|
|
|
this.address = '',
|
|
|
|
|
this.phone = '',
|
|
|
|
|
this.email = '',
|
|
|
|
|
this.note = '',
|
|
|
|
|
this.createdBy,
|
|
|
|
|
this.updatedAt,
|
2026-08-06 16:14:30 +02:00
|
|
|
this.lat,
|
|
|
|
|
this.lon,
|
|
|
|
|
this.eovY,
|
|
|
|
|
this.eovX,
|
2026-07-08 13:32:04 +02:00
|
|
|
});
|
|
|
|
|
|
2026-08-06 16:14:30 +02:00
|
|
|
bool get hasLocation => lat != null && lon != null;
|
|
|
|
|
|
|
|
|
|
Contact copyWith(
|
|
|
|
|
{String? name,
|
|
|
|
|
String? address,
|
|
|
|
|
String? phone,
|
|
|
|
|
String? email,
|
|
|
|
|
String? note,
|
|
|
|
|
double? lat,
|
|
|
|
|
double? lon,
|
|
|
|
|
double? eovY,
|
|
|
|
|
double? eovX,
|
|
|
|
|
bool clearLocation = false}) =>
|
2026-07-08 13:32:04 +02:00
|
|
|
Contact(
|
|
|
|
|
id: id,
|
2026-07-08 22:13:30 +02:00
|
|
|
projectId: projectId,
|
2026-07-08 13:32:04 +02:00
|
|
|
name: name ?? this.name,
|
|
|
|
|
address: address ?? this.address,
|
|
|
|
|
phone: phone ?? this.phone,
|
|
|
|
|
email: email ?? this.email,
|
|
|
|
|
note: note ?? this.note,
|
|
|
|
|
createdBy: createdBy,
|
|
|
|
|
updatedAt: updatedAt,
|
2026-08-06 16:14:30 +02:00
|
|
|
lat: clearLocation ? null : (lat ?? this.lat),
|
|
|
|
|
lon: clearLocation ? null : (lon ?? this.lon),
|
|
|
|
|
eovX: clearLocation ? null : (eovX ?? this.eovX),
|
|
|
|
|
eovY: clearLocation ? null : (eovY ?? this.eovY),
|
2026-07-08 13:32:04 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/// Beszúráshoz/frissítéshez — az id-t csak akkor küldjük, ha van
|
|
|
|
|
/// (frissítésnél), a szerveroldali mezőket (created_by, updated_at)
|
|
|
|
|
/// sosem a kliens állítja.
|
|
|
|
|
Map<String, dynamic> toWriteMap() => {
|
|
|
|
|
if (id != null) 'id': id,
|
2026-07-08 22:13:30 +02:00
|
|
|
'project_id': projectId,
|
2026-07-08 13:32:04 +02:00
|
|
|
'name': name.trim(),
|
|
|
|
|
'address': address.trim(),
|
|
|
|
|
'phone': phone.trim(),
|
|
|
|
|
'email': email.trim(),
|
|
|
|
|
'note': note.trim(),
|
2026-08-06 16:14:30 +02:00
|
|
|
'lat': lat,
|
|
|
|
|
'lon': lon,
|
|
|
|
|
'eov_y': eovY,
|
|
|
|
|
'eov_x': eovX,
|
2026-07-08 13:32:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
factory Contact.fromMap(Map<String, dynamic> m) => Contact(
|
|
|
|
|
id: m['id'] as String?,
|
2026-07-08 22:13:30 +02:00
|
|
|
projectId: m['project_id'] as String,
|
2026-07-08 13:32:04 +02:00
|
|
|
name: (m['name'] as String?) ?? '',
|
|
|
|
|
address: (m['address'] as String?) ?? '',
|
|
|
|
|
phone: (m['phone'] as String?) ?? '',
|
|
|
|
|
email: (m['email'] as String?) ?? '',
|
|
|
|
|
note: (m['note'] as String?) ?? '',
|
|
|
|
|
createdBy: m['created_by'] as String?,
|
|
|
|
|
updatedAt: m['updated_at'] != null
|
|
|
|
|
? DateTime.tryParse(m['updated_at'] as String)
|
|
|
|
|
: null,
|
2026-08-06 16:14:30 +02:00
|
|
|
lat: (m['lat'] as num?)?.toDouble(),
|
|
|
|
|
lon: (m['lon'] as num?)?.toDouble(),
|
|
|
|
|
eovY: (m['eov_y'] as num?)?.toDouble(),
|
|
|
|
|
eovX: (m['eov_x'] as num?)?.toDouble(),
|
2026-07-08 13:32:04 +02:00
|
|
|
);
|
|
|
|
|
}
|