import 'package:equatable/equatable.dart'; /// Model representing an action template from the API /// Used for dynamic form generation when selecting action types class ActionTemplate extends Equatable { final String actionName; final List parameters; final String description; final String category; final bool requiredCaption; final bool supportsDelay; final Map? parameterTypes; const ActionTemplate({ required this.actionName, required this.parameters, required this.description, required this.category, this.requiredCaption = true, this.supportsDelay = true, this.parameterTypes, }); factory ActionTemplate.fromJson(Map json) { return ActionTemplate( actionName: json['action_name'] as String, parameters: (json['parameters'] as List) .map((e) => e.toString()) .toList(), description: json['description'] as String, category: json['category'] as String, requiredCaption: json['required_caption'] as bool? ?? true, supportsDelay: json['supports_delay'] as bool? ?? true, parameterTypes: json['parameter_types'] != null ? Map.from(json['parameter_types'] as Map) : null, ); } Map toJson() { return { 'action_name': actionName, 'parameters': parameters, 'description': description, 'category': category, 'required_caption': requiredCaption, 'supports_delay': supportsDelay, if (parameterTypes != null) 'parameter_types': parameterTypes, }; } @override List get props => [ actionName, parameters, description, category, requiredCaption, supportsDelay, parameterTypes, ]; } /// Model representing a server (G-Core or GeViScope) class ServerInfo extends Equatable { final String id; final String alias; final bool enabled; const ServerInfo({ required this.id, required this.alias, required this.enabled, }); factory ServerInfo.fromJson(Map json) { return ServerInfo( id: json['id'].toString(), alias: json['alias'] as String, enabled: json['enabled'] as bool, ); } Map toJson() { return { 'id': id, 'alias': alias, 'enabled': enabled, }; } @override List get props => [id, alias, enabled]; } /// Model for servers information class ServersInfo extends Equatable { final List gcoreServers; final List gscServers; const ServersInfo({ required this.gcoreServers, required this.gscServers, }); factory ServersInfo.fromJson(Map json) { return ServersInfo( gcoreServers: (json['gcore_servers'] as List?) ?.map((e) => ServerInfo.fromJson(e as Map)) .toList() ?? [], gscServers: (json['gsc_servers'] as List?) ?.map((e) => ServerInfo.fromJson(e as Map)) .toList() ?? [], ); } @override List get props => [gcoreServers, gscServers]; } /// Model for action categories response class ActionCategoriesResponse extends Equatable { final Map> categories; final int totalCategories; final int totalActions; final ServersInfo servers; final List gscSpecificCategories; const ActionCategoriesResponse({ required this.categories, required this.totalCategories, required this.totalActions, required this.servers, this.gscSpecificCategories = const [], }); factory ActionCategoriesResponse.fromJson(Map json) { final categoriesMap = json['categories'] as Map; final categories = categoriesMap.map( (key, value) => MapEntry( key, (value as List).map((e) => e.toString()).toList(), ), ); return ActionCategoriesResponse( categories: categories, totalCategories: json['total_categories'] as int, totalActions: json['total_actions'] as int, servers: ServersInfo.fromJson(json['servers'] as Map? ?? {}), gscSpecificCategories: (json['gsc_specific_categories'] as List?) ?.map((e) => e.toString()) .toList() ?? [], ); } /// Get all action names sorted by category List getActionsForCategory(String category) { return categories[category] ?? []; } /// Get list of all category names sorted List get categoryNames { final names = categories.keys.toList(); names.sort(); return names; } @override List get props => [categories, totalCategories, totalActions, servers, gscSpecificCategories]; }