import '../../../core/api_gateway.dart'; /// One template from the server catalogue. /// /// The server owns this record: [key], [name], [description], [source] and /// [scheduled] are read from it verbatim and every other field is kept in /// [raw], so a later view or round-trip never loses fields this client does not /// understand yet. Loading a template is a read; it never publishes or runs it. class TemplateEntry { const TemplateEntry({ required this.key, required this.name, required this.description, required this.source, required this.scheduled, required this.raw, }); factory TemplateEntry.fromJson(JsonMap json) { final raw = _frozenMap(json); return TemplateEntry( key: _text(raw['key']), name: _text(raw['name']), description: _text(raw['description']), source: _text(raw['source']), scheduled: raw['scheduled'] == true, raw: raw, ); } /// The stable catalogue key the gallery selects on. final String key; final String name; final String description; /// The template's complete, untrimmed definition source. final String source; /// Whether the source declares a schedule (the summary's "Includes a schedule"). final bool scheduled; /// Every field the server sent, including fields this client does not model. /// Deeply unmodifiable: nested maps and lists are copied into read-only /// collections too, so a view cannot mutate the server reply through it. final JsonMap raw; static String _text(dynamic value) => value == null ? '' : '$value'; static JsonMap _frozenMap(Map json) => Map.unmodifiable( json.map((key, value) => MapEntry(key, _frozen(value))), ); static dynamic _frozen(dynamic value) { if (value is Map) { return _frozenMap(Map.from(value)); } if (value is List) { return List.unmodifiable(value.map(_frozen)); } return value; } }