class BodySymptomResponseModel {
  final DataDetails? dataDetails;

  BodySymptomResponseModel({
    this.dataDetails,
  });

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

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

class DataDetails {
  final List<OrganSymptomResult>? result;
  final int? id;
  final dynamic exception;
  final int? status;
  final bool? isCanceled;
  final bool? isCompleted;
  final bool? isCompletedSuccessfully;
  final int? creationOptions;
  final dynamic asyncState;
  final bool? isFaulted;

  DataDetails({
    this.result,
    this.id,
    this.exception,
    this.status,
    this.isCanceled,
    this.isCompleted,
    this.isCompletedSuccessfully,
    this.creationOptions,
    this.asyncState,
    this.isFaulted,
  });

  factory DataDetails.fromJson(Map<String, dynamic> json) {
    return DataDetails(
      result: json['Result'] != null ? (json['Result'] as List).map((item) => OrganSymptomResult.fromJson(item)).toList() : null,
      id: json['Id'],
      exception: json['Exception'],
      status: json['Status'],
      isCanceled: json['IsCanceled'],
      isCompleted: json['IsCompleted'],
      isCompletedSuccessfully: json['IsCompletedSuccessfully'],
      creationOptions: json['CreationOptions'],
      asyncState: json['AsyncState'],
      isFaulted: json['IsFaulted'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'Result': result?.map((item) => item.toJson()).toList(),
      'Id': id,
      'Exception': exception,
      'Status': status,
      'IsCanceled': isCanceled,
      'IsCompleted': isCompleted,
      'IsCompletedSuccessfully': isCompletedSuccessfully,
      'CreationOptions': creationOptions,
      'AsyncState': asyncState,
      'IsFaulted': isFaulted,
    };
  }
}

class OrganSymptomResult {
  final String? name;
  final List<BodySymptom>? bodySymptoms;

  OrganSymptomResult({
    this.name,
    this.bodySymptoms,
  });

  factory OrganSymptomResult.fromJson(Map<String, dynamic> json) {
    return OrganSymptomResult(
      name: json['name'],
      bodySymptoms: json['bodySymptoms'] != null ? (json['bodySymptoms'] as List).map((item) => BodySymptom.fromJson(item)).toList() : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'name': name,
      'bodySymptoms': bodySymptoms?.map((item) => item.toJson()).toList(),
    };
  }
}

class BodySymptom {
  final String? id;
  final String? type;
  final String? symptomsName;
  final String? name;
  final String? commonName;
  final String? nameAr;
  final String? commonNameAr;

  BodySymptom({
    this.id,
    this.type,
    this.symptomsName,
    this.name,
    this.commonName,
    this.nameAr,
    this.commonNameAr,
  });

  factory BodySymptom.fromJson(Map<String, dynamic> json) {
    return BodySymptom(
      id: json['Id'],
      type: json['type'],
      symptomsName: json['symptoms_name'],
      name: json['name'],
      commonName: json['common_name'],
      nameAr: json['nameAr'],
      commonNameAr: json['common_nameAr'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'Id': id,
      'type': type,
      'symptoms_name': symptomsName,
      'name': name,
      'common_name': commonName,
      'nameAr': nameAr,
      'common_nameAr': commonNameAr,
    };
  }

  // Helper method to get display name based on locale
  String getDisplayName(bool isArabic) {
    if (isArabic) {
      return commonNameAr ?? nameAr ?? commonName ?? name ?? '';
    }
    return commonName ?? name ?? '';
  }
}
