import 'package:oc_front/models/abstract.dart'; import 'package:oc_front/models/response.dart'; import 'package:oc_front/models/workflow.dart'; import 'package:oc_front/models/workspace.dart'; /* based on : type CollaborativeAreaRule struct { ShareMode string `json:"share_mode,omitempty" bson:"share_mode,omitempty"` // Share is the share of the rule CreatedAt time.Time `json:"created_at,omitempty" bson:"created_at,omitempty"` // CreatedAt is the time the rule was created Creator string `json:"creator,omitempty" bson:"creator,omitempty"` // Creator is the creator of the rule ExploitedBy string `json:"exploited_by,omitempty" bson:"exploited_by,omitempty"` // ExploitedBy is the exploited by of the rule } */ class CollaborativeAreaRule extends SerializerDeserializer { String? shareMode; DateTime? createdAt; String? creator; String? exploitedBy; CollaborativeAreaRule( {this.shareMode, this.createdAt, this.creator, this.exploitedBy,}); @override CollaborativeAreaRule deserialize(dynamic json) { try { json = json as Map; } catch (e) { return CollaborativeAreaRule(); } return CollaborativeAreaRule( shareMode: json.containsKey("share_mode") ? json["share_mode"] : null, createdAt: json.containsKey("created_at") ? DateTime.parse(json["created_at"]) : null, creator: json.containsKey("creator") ? json["creator"] : null, exploitedBy: json.containsKey("exploited_by") ? json["exploited_by"] : null, ); } @override Map serialize() => { "share_mode": shareMode, "created_at": createdAt?.toIso8601String(), "creator": creator, "exploited_by": exploitedBy, }; } class CollaborativeArea extends SerializerDeserializer { String? id; String? name; String? description; String? creatorID; String? version; Map attributes = {}; List workspaces = []; List workflows = []; List peers = []; List rules = []; CollaborativeAreaRule? rule; CollaborativeArea( {this.id, this.name, this.description, this.creatorID, this.version, this.attributes = const {}, this.workspaces = const [], this.workflows = const [], this.peers = const [], this.rule, this.rules = const []}); @override deserialize(dynamic json) { try { json = json as Map; } catch (e) { return CollaborativeArea(); } return CollaborativeArea( rule : json.containsKey("collaborative_area") ? CollaborativeAreaRule().deserialize(json["collaborative_area"]) : CollaborativeAreaRule(), id: json.containsKey("id") ? json["id"] : null, name: json.containsKey("name") ? json["name"] : null, description: json.containsKey("description") ? json["description"] : null, version: json.containsKey("version") ? json["version"] : null, attributes: json.containsKey("attributes") ? json["attributes"] : {}, workspaces: json.containsKey("shared_workspaces") ? fromListJson(json["shared_workspaces"], Workspace()) : [], workflows: json.containsKey("shared_workflows") ? fromListJson(json["shared_workflows"], Workflow()) : [], peers: json.containsKey("shared_peers") ? fromListJson(json["shared_peers"], Peer()) : [], rules: json.containsKey("rules") ? json["rules"] : [], ); } @override Map serialize() => { "id": id, "name": name, "description": description, "creator_id": creatorID, "version": version, "attributes": attributes, "rule": rule?.serialize(), "workspaces": workspaces.map((e) => e.id).toList(), "workflows": workflows.map((e) => e.id).toList(), "peers": peers.map((e) => e.id).toList(), "rules": rules.map((e) => e.id).toList(), }; } class Rule extends SerializerDeserializer { String? id; String? name; String? description; Rule( {this.id, this.name, this.description,}); @override deserialize(dynamic json) { try { json = json as Map; } catch (e) { return Rule(); } return Rule( id: json.containsKey("id") ? json["id"] : null, name: json.containsKey("name") ? json["name"] : null, description: json.containsKey("description") ? json["description"] : null, ); } @override Map serialize() => { "id": id, "name": name, "description": description, }; } class Peer extends SerializerDeserializer implements ShallowData { String? id; String? name; Peer( {this.id, this.name,}); @override String getID() => id ?? ""; @override String getName() => name ?? ""; @override deserialize(dynamic json) { try { json = json as Map; } catch (e) { return Peer(); } return Peer( id: json.containsKey("id") ? json["id"] : null, name: json.containsKey("name") ? json["name"] : null, ); } @override Map serialize() => { "id": id, "name": name, }; }