class RationaleResponseModel {
  final RationaleDataDetails? dataDetails;

  RationaleResponseModel({this.dataDetails});

  factory RationaleResponseModel.fromJson(Map<String, dynamic> json) {
    return RationaleResponseModel(
      dataDetails: json['dataDetails'] != null
          ? RationaleDataDetails.fromJson(json['dataDetails'])
          : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'dataDetails': dataDetails?.toJson(),
    };
  }
}

class RationaleDataDetails {
  final String? type;
  final List<RationaleObservationParam>? observationParams;
  final List<RationaleConditionParam>? conditionParams;
  final String? message;
  final List<String>? errorList;
  final int? id;
  final String? language;
  final String? generalId;
  final String? createDate;
  final String? lastEditDate;
  final String? createdBy;
  final String? lastEditBy;
  final bool? active;
  final int? sortOrder;
  final int? userType;
  final String? userId;

  RationaleDataDetails({
    this.type,
    this.observationParams,
    this.conditionParams,
    this.message,
    this.errorList,
    this.id,
    this.language,
    this.generalId,
    this.createDate,
    this.lastEditDate,
    this.createdBy,
    this.lastEditBy,
    this.active,
    this.sortOrder,
    this.userType,
    this.userId,
  });

  factory RationaleDataDetails.fromJson(Map<String, dynamic> json) {
    return RationaleDataDetails(
      type: json['type'],
      observationParams: json['observation_params'] != null
          ? (json['observation_params'] as List)
              .map((item) => RationaleObservationParam.fromJson(item))
              .toList()
          : null,
      conditionParams: json['condition_params'] != null
          ? (json['condition_params'] as List)
              .map((item) => RationaleConditionParam.fromJson(item))
              .toList()
          : null,
      message: json['Message'],
      errorList: json['ErrorList'] != null
          ? List<String>.from(json['ErrorList'])
          : null,
      id: json['Id'],
      language: json['language'],
      generalId: json['generalId'],
      createDate: json['CreateDate'],
      lastEditDate: json['LastEditDate'],
      createdBy: json['CreatedBy'],
      lastEditBy: json['LastEditBy'],
      active: json['Active'],
      sortOrder: json['SortOrder'],
      userType: json['userType'],
      userId: json['userId'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'type': type,
      'observation_params': observationParams?.map((item) => item.toJson()).toList(),
      'condition_params': conditionParams?.map((item) => item.toJson()).toList(),
      'Message': message,
      'ErrorList': errorList,
      'Id': id,
      'language': language,
      'generalId': generalId,
      'CreateDate': createDate,
      'LastEditDate': lastEditDate,
      'CreatedBy': createdBy,
      'LastEditBy': lastEditBy,
      'Active': active,
      'SortOrder': sortOrder,
      'userType': userType,
      'userId': userId,
    };
  }
}

class RationaleObservationParam {
  final String? id;
  final String? name;
  final String? commonName;

  RationaleObservationParam({
    this.id,
    this.name,
    this.commonName,
  });

  factory RationaleObservationParam.fromJson(Map<String, dynamic> json) {
    return RationaleObservationParam(
      id: json['id'],
      name: json['name'],
      commonName: json['common_name'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'common_name': commonName,
    };
  }

  // Helper method to get display name
  String getDisplayName() {
    return commonName ?? name ?? '';
  }
}

class RationaleConditionParam {
  final String? id;
  final String? name;
  final String? commonName;

  RationaleConditionParam({
    this.id,
    this.name,
    this.commonName,
  });

  factory RationaleConditionParam.fromJson(Map<String, dynamic> json) {
    return RationaleConditionParam(
      id: json['id'],
      name: json['name'],
      commonName: json['common_name'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'common_name': commonName,
    };
  }

  // Helper method to get display name
  String getDisplayName() {
    return commonName ?? name ?? '';
  }
}

