import 'package:shared_preferences/shared_preferences.dart'; class Collection { int id; String description; String collectionName; Collection({ required this.id, required this.description, required this.collectionName, }); factory Collection.fromJson(Map<String, dynamic> json) { return Collection( id: json['id'], collectionName: json['collectionName'], description: json['description'], ); } @override String toString(){ return collectionName; } } class Device{ int id; String urn; Device(this.id, this.urn); factory Device.fromJson(Map<String, dynamic> parsedJson){ return Device( parsedJson['id'] as int, parsedJson['urn'] as String); } @override String toString(){ return '{ ${this.id}, ${this.urn} }'; } } class Event{ int id; String urn; String label; String type; String description; String status; Event( this.id, this.urn, this.label, this.type, this.description, this.status ); factory Event.fromJson(Map<String, dynamic> parsedJson){ return Event( parsedJson['id'] as int, parsedJson['urn'] as String, parsedJson['label'] as String, parsedJson['type'] as String, parsedJson['description'] as String, parsedJson['status'] as String ); } @override String toString(){ return '{ ${this.id}, ${this.urn}, ${this.label}, ${this.type}, ${this.description}, ${this.status} }'; } } class EventType{ int id; String name; EventType( this.id, this.name ); factory EventType.fromJson(Map<String, dynamic> parsedJson){ return EventType(parsedJson['id'] as int, parsedJson['name'] as String); } } abstract class CollectionStoreBase { List<Collection> store = []; } class CollectionStoreInstance extends CollectionStoreBase { static final CollectionStoreInstance _instance = CollectionStoreInstance ._internal(); factory CollectionStoreInstance() { return _instance; } CollectionStoreInstance._internal() { store = []; } void reset() { store = []; } } abstract class DeviceStoreBase { List<Device> store = []; int getDeviceIdFromUrn(String urn) { for (var device in store) { if (device.urn == urn) { return device.id; } } throw Exception('Device with urn:' + urn + ' was not found.'); } void reset(){ store = []; } } abstract class EventStoreBase{ List<Event> store = []; } abstract class EventCurrentBase{ Event store = Event(0, 'urn0', '', '', '', 'PENDING'); } abstract class CollectionCurrentBase{ Collection store = Collection(id: -1, description: 'description', collectionName: 'name'); } abstract class EventTypeStoreBase{ List<EventType> store = []; int getEventIdFromName(String name) { for (var eventType in store) { if (eventType.name == name) { return eventType.id; } } throw Exception('Event with name :' + name + ' was not found.'); } } class EventStoreInstance extends EventStoreBase { static final EventStoreInstance _instance = EventStoreInstance._internal(); factory EventStoreInstance() { return _instance; } EventStoreInstance._internal() { store = []; } void reset(){ store = []; } } class EventCurrentInstance extends EventCurrentBase { static final EventCurrentInstance _instance = EventCurrentInstance._internal(); factory EventCurrentInstance(){ return _instance; } EventCurrentInstance._internal(){ store = Event(-1, 'urn0', '', '', '', 'PENDING'); } void reset(){ store = Event(-1, 'urn0', '', '', '', 'PENDING'); } } class CollectionCurrentInstance extends CollectionCurrentBase { static final CollectionCurrentInstance _instance = CollectionCurrentInstance._internal(); factory CollectionCurrentInstance(){ return _instance; } CollectionCurrentInstance._internal(){ store = Collection(collectionName: 'name', description: 'description', id: -1); } void reset(){ store = Collection(collectionName: 'name', description: 'description', id: -1); } } class EventTypeStoreInstance extends EventTypeStoreBase{ static final EventTypeStoreInstance _instance = EventTypeStoreInstance._internal(); factory EventTypeStoreInstance(){ return _instance; } EventTypeStoreInstance._internal(){ store = []; } void reset(){ store = []; } } class DeviceStoreInstance extends DeviceStoreBase{ static final DeviceStoreInstance _instance = DeviceStoreInstance._internal(); factory DeviceStoreInstance(){ return _instance; } DeviceStoreInstance._internal(){ store = []; } }