import 'ResponseState.dart';

class SystemResponse {
  String key;

  String value;

  String description;

  ResponseState state;

  SystemResponse(this.key, this.value, this.description, this.state);

  factory SystemResponse.fromJsonMap(Map<String, dynamic> json) {
    return SystemResponse(
      json['key'] ?? "",
      json['value'] ?? "",
      json['description'] ?? "",
      _state(json['state']),
    );
  }

  static ResponseState _state(String? name) {
    for (ResponseState value in ResponseState.values) {
      if (value.name == name) {
        return value;
      }
    }
    return ResponseState.Success;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['key'] = key;
    data['value'] = value;
    data['description'] = description;
    data['state'] = state.name;
    return data;
  }
}
