import 'package:json_annotation/json_annotation.dart'; part 'udp_package.g.dart'; @JsonSerializable() class UdpPackage { final String id; final String name; final String data; // Support for multiple IP addresses final List ipAddresses; // Broadcast mode flag @JsonKey(defaultValue: false) final bool isBroadcast; // Legacy field for backward compatibility - kept for migration @JsonKey(includeFromJson: true, includeToJson: false) final String? ipAddress; UdpPackage({ required this.id, required this.name, required this.data, List? ipAddresses, this.isBroadcast = false, this.ipAddress, }) : ipAddresses = ipAddresses ?? (ipAddress != null ? [ipAddress] : ['127.0.0.1']); factory UdpPackage.fromJson(Map json) { // Handle migration from old format if (json.containsKey('ipAddress') && !json.containsKey('ipAddresses')) { json['ipAddresses'] = [json['ipAddress']]; } return _$UdpPackageFromJson(json); } Map toJson() => _$UdpPackageToJson(this); UdpPackage copyWith({ String? id, String? name, String? data, List? ipAddresses, bool? isBroadcast, }) { return UdpPackage( id: id ?? this.id, name: name ?? this.name, data: data ?? this.data, ipAddresses: ipAddresses ?? this.ipAddresses, isBroadcast: isBroadcast ?? this.isBroadcast, ); } }