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