import 'package:uuid/uuid.dart'; /// Érzékelő-csatorna: a MŰSZER geometriája — melyik csatornaszám melyik /// vonal/állomás fizikai pontjához tartozik. /// /// SZÁNDÉKOSAN önálló modell (nem a StakeoutPoint kiterjesztése): az /// adat forrása lehet SPS-import (a műszer geometria-exportja), de /// származhat máshonnan is (kézi rögzítés, jövőbeli más formátum). /// A kitűzési (GNSS-szel mért) pontokkal a (lineId, station) párossal /// vetjük össze FUTÁSIDŐBEN (lásd StakeoutService), nem tárolunk /// másolatot a mért pozícióból — így sosem megy szét a két adat. class SensorChannel { final int? id; final String uuid; final int projectId; final int channel; final String lineId; final int station; /// Terv-pozíció az SPS R-fájlból (ha volt hozzá tartozó vevőpont-sor). /// Null, ha csak a csatorna-hozzárendelés ismert (pl. csak X-fájl volt), /// ilyenkor a GNSS-mért kitűzési pont adja az egyetlen pozíciót. final double? planEovY; final double? planEovX; final double? planLat; final double? planLon; final String source; // 'sps' | 'manual' final String? importBatch; // egy import-menet azonosítója (törléshez) final DateTime createdAt; final DateTime updatedAt; SensorChannel({ this.id, String? uuid, required this.projectId, required this.channel, required this.lineId, required this.station, this.planEovY, this.planEovX, this.planLat, this.planLon, this.source = 'sps', this.importBatch, DateTime? createdAt, DateTime? updatedAt, }) : uuid = uuid ?? const Uuid().v4(), createdAt = createdAt ?? DateTime.now(), updatedAt = updatedAt ?? DateTime.now(); bool get hasPlanPosition => planEovY != null && planEovX != null; Map toMap() => { if (id != null) 'id': id, 'uuid': uuid, 'project_id': projectId, 'channel': channel, 'line_id': lineId, 'station': station, 'plan_eov_y': planEovY, 'plan_eov_x': planEovX, 'plan_lat': planLat, 'plan_lon': planLon, 'source': source, 'import_batch': importBatch, 'created_at': createdAt.toIso8601String(), 'updated_at': updatedAt.toIso8601String(), }; factory SensorChannel.fromMap(Map m) => SensorChannel( id: m['id'] as int?, uuid: m['uuid'] as String, projectId: m['project_id'] as int, channel: m['channel'] as int, lineId: (m['line_id'] as String?) ?? '', station: m['station'] as int, planEovY: (m['plan_eov_y'] as num?)?.toDouble(), planEovX: (m['plan_eov_x'] as num?)?.toDouble(), planLat: (m['plan_lat'] as num?)?.toDouble(), planLon: (m['plan_lon'] as num?)?.toDouble(), source: (m['source'] as String?) ?? 'sps', importBatch: m['import_batch'] as String?, createdAt: DateTime.tryParse((m['created_at'] as String?) ?? '') ?? DateTime.now(), updatedAt: DateTime.tryParse((m['updated_at'] as String?) ?? '') ?? DateTime.now(), ); }