import 'view_port.dart';

class LayoutUnit {
  String _key = '';
  List<LayoutViewPort>? _viewPorts;

  String get key => _key;
  List<LayoutViewPort> get viewPorts => _viewPorts ?? const [];

  LayoutUnit();

  factory LayoutUnit.fromJson(Map<String, dynamic> map) {
    final instance = LayoutUnit();
    instance._key = map['k'] ?? '';
    instance._loadViewPorts(map['ViewPorts']);
    return instance;
  }

  void _loadViewPorts(dynamic data) {
    final List<LayoutViewPort> arr = [];

    if (data != null && data is List) {
      final List<dynamic> jArr = data;
      for (final item in jArr) {
        arr.add(LayoutViewPort.fromJson(item));
      }
    }
    _viewPorts = arr;
  }
}
