class FoodDataQueryResponse { int totalHits; int currentPage; int totalPages; List pageList; FoodSearchCriteria foodSearchCriteria; List foods; Aggregations aggregations; FoodDataQueryResponse({ required this.totalHits, required this.currentPage, required this.totalPages, required this.pageList, required this.foodSearchCriteria, required this.foods, required this.aggregations, }); factory FoodDataQueryResponse.fromJson(Map json) => FoodDataQueryResponse( totalHits: json["totalHits"], currentPage: json["currentPage"], totalPages: json["totalPages"], pageList: List.from(json["pageList"].map((x) => x)), foodSearchCriteria: FoodSearchCriteria.fromJson(json["foodSearchCriteria"]), foods: List.from(json["foods"].map((x) => FoodData.fromJson(x))), aggregations: Aggregations.fromJson(json["aggregations"]), ); Map toJson() => { "totalHits": totalHits, "currentPage": currentPage, "totalPages": totalPages, "pageList": List.from(pageList.map((x) => x)), "foodSearchCriteria": foodSearchCriteria.toJson(), "foods": List.from(foods.map((x) => x.toJson())), "aggregations": aggregations.toJson(), }; } class Aggregations { DataType dataType; Nutrients nutrients; Aggregations({ required this.dataType, required this.nutrients, }); factory Aggregations.fromJson(Map json) => Aggregations( dataType: DataType.fromJson(json["dataType"]), nutrients: Nutrients.fromJson(json["nutrients"]), ); Map toJson() => { "dataType": dataType.toJson(), "nutrients": nutrients.toJson(), }; } class DataType { int branded; int surveyFndds; int srLegacy; int foundation; DataType({ required this.branded, required this.surveyFndds, required this.srLegacy, required this.foundation, }); factory DataType.fromJson(Map json) => DataType( branded: json["Branded"], surveyFndds: json["Survey (FNDDS)"], srLegacy: json["SR Legacy"], foundation: json["Foundation"], ); Map toJson() => { "Branded": branded, "Survey (FNDDS)": surveyFndds, "SR Legacy": srLegacy, "Foundation": foundation, }; } class Nutrients { Nutrients(); factory Nutrients.fromJson(Map json) => Nutrients(); Map toJson() => {}; } class FoodSearchCriteria { List dataType; String query; String generalSearchInput; int pageNumber; String sortBy; String sortOrder; int numberOfResultsPerPage; int pageSize; bool requireAllWords; List foodTypes; FoodSearchCriteria({ required this.dataType, required this.query, required this.generalSearchInput, required this.pageNumber, required this.sortBy, required this.sortOrder, required this.numberOfResultsPerPage, required this.pageSize, required this.requireAllWords, required this.foodTypes, }); factory FoodSearchCriteria.fromJson(Map json) => FoodSearchCriteria( dataType: List.from(json["dataType"].map((x) => typeValues.map[x]!)), query: json["query"], generalSearchInput: json["generalSearchInput"], pageNumber: json["pageNumber"], sortBy: json["sortBy"], sortOrder: json["sortOrder"], numberOfResultsPerPage: json["numberOfResultsPerPage"], pageSize: json["pageSize"], requireAllWords: json["requireAllWords"], foodTypes: List.from(json["foodTypes"].map((x) => typeValues.map[x]!)), ); Map toJson() => { "dataType": List.from(dataType.map((x) => typeValues.reverse[x])), "query": query, "generalSearchInput": generalSearchInput, "pageNumber": pageNumber, "sortBy": sortBy, "sortOrder": sortOrder, "numberOfResultsPerPage": numberOfResultsPerPage, "pageSize": pageSize, "requireAllWords": requireAllWords, "foodTypes": List.from(foodTypes.map((x) => typeValues.reverse[x])), }; } enum Type { FOUNDATION, SR_LEGACY } final typeValues = EnumValues({"Foundation": Type.FOUNDATION, "SR Legacy": Type.SR_LEGACY}); class FoodData { int fdcId; String description; String commonNames; String additionalDescriptions; Type dataType; int ndbNumber; DateTime publishedDate; FoodCategory? foodCategory; DateTime? mostRecentAcquisitionDate; String allHighlightFields; double score; List microbes; List foodNutrients; List finalFoodInputFoods; List foodMeasures; List foodAttributes; List foodAttributeTypes; List foodVersionIds; FoodData({ required this.fdcId, required this.description, required this.commonNames, required this.additionalDescriptions, required this.dataType, required this.ndbNumber, required this.publishedDate, required this.foodCategory, this.mostRecentAcquisitionDate, required this.allHighlightFields, required this.score, required this.microbes, required this.foodNutrients, required this.finalFoodInputFoods, required this.foodMeasures, required this.foodAttributes, required this.foodAttributeTypes, required this.foodVersionIds, }); factory FoodData.fromJson(Map json) => FoodData( fdcId: json["fdcId"], description: json["description"], commonNames: json["commonNames"], additionalDescriptions: json["additionalDescriptions"], dataType: typeValues.map[json["dataType"]]!, ndbNumber: json["ndbNumber"], publishedDate: DateTime.parse(json["publishedDate"]), foodCategory: foodCategoryValues.map[json["foodCategory"]], mostRecentAcquisitionDate: json["mostRecentAcquisitionDate"] == null ? null : DateTime.parse(json["mostRecentAcquisitionDate"]), allHighlightFields: json["allHighlightFields"], score: json["score"]?.toDouble(), microbes: List.from(json["microbes"].map((x) => x)), foodNutrients: List.from( json["foodNutrients"].map((x) => FoodNutrient.fromJson(x))), finalFoodInputFoods: List.from(json["finalFoodInputFoods"].map((x) => x)), foodMeasures: List.from(json["foodMeasures"].map((x) => x)), foodAttributes: List.from(json["foodAttributes"].map((x) => x)), foodAttributeTypes: List.from(json["foodAttributeTypes"].map((x) => x)), foodVersionIds: List.from(json["foodVersionIds"].map((x) => x)), ); Map toJson() => { "fdcId": fdcId, "description": description, "commonNames": commonNames, "additionalDescriptions": additionalDescriptions, "dataType": typeValues.reverse[dataType], "ndbNumber": ndbNumber, "publishedDate": "${publishedDate.year.toString().padLeft(4, '0')}-${publishedDate.month.toString().padLeft(2, '0')}-${publishedDate.day.toString().padLeft(2, '0')}", "foodCategory": foodCategoryValues.reverse[foodCategory], "mostRecentAcquisitionDate": "${mostRecentAcquisitionDate!.year.toString().padLeft(4, '0')}-${mostRecentAcquisitionDate!.month.toString().padLeft(2, '0')}-${mostRecentAcquisitionDate!.day.toString().padLeft(2, '0')}", "allHighlightFields": allHighlightFields, "score": score, "microbes": List.from(microbes.map((x) => x)), "foodNutrients": List.from(foodNutrients.map((x) => x.toJson())), "finalFoodInputFoods": List.from(finalFoodInputFoods.map((x) => x)), "foodMeasures": List.from(foodMeasures.map((x) => x)), "foodAttributes": List.from(foodAttributes.map((x) => x)), "foodAttributeTypes": List.from(foodAttributeTypes.map((x) => x)), "foodVersionIds": List.from(foodVersionIds.map((x) => x)), }; } enum FoodCategory { DAIRY_AND_EGG_PRODUCTS } final foodCategoryValues = EnumValues({"Dairy and Egg Products": FoodCategory.DAIRY_AND_EGG_PRODUCTS}); class FoodNutrient { int nutrientId; String nutrientName; String nutrientNumber; UnitName unitName; DerivationCode? derivationCode; String? derivationDescription; int? derivationId; double? value; int? foodNutrientSourceId; String? foodNutrientSourceCode; FoodNutrientSourceDescription? foodNutrientSourceDescription; int rank; int indentLevel; int foodNutrientId; int? dataPoints; double? min; double? max; double? median; FoodNutrient({ required this.nutrientId, required this.nutrientName, required this.nutrientNumber, required this.unitName, this.derivationCode, this.derivationDescription, this.derivationId, this.value, this.foodNutrientSourceId, this.foodNutrientSourceCode, this.foodNutrientSourceDescription, required this.rank, required this.indentLevel, required this.foodNutrientId, this.dataPoints, this.min, this.max, this.median, }); factory FoodNutrient.fromJson(Map json) => FoodNutrient( nutrientId: json["nutrientId"], nutrientName: json["nutrientName"], nutrientNumber: json["nutrientNumber"], unitName: unitNameValues.map[json["unitName"]]!, derivationCode: derivationCodeValues.map[json["derivationCode"]]!, derivationDescription: json["derivationDescription"], derivationId: json["derivationId"], value: json["value"]?.toDouble(), foodNutrientSourceId: json["foodNutrientSourceId"], foodNutrientSourceCode: json["foodNutrientSourceCode"], foodNutrientSourceDescription: foodNutrientSourceDescriptionValues .map[json["foodNutrientSourceDescription"]]!, rank: json["rank"], indentLevel: json["indentLevel"], foodNutrientId: json["foodNutrientId"], dataPoints: json["dataPoints"], min: json["min"]?.toDouble(), max: json["max"]?.toDouble(), median: json["median"]?.toDouble(), ); Map toJson() => { "nutrientId": nutrientId, "nutrientName": nutrientName, "nutrientNumber": nutrientNumber, "unitName": unitNameValues.reverse[unitName], "derivationCode": derivationCodeValues.reverse[derivationCode], "derivationDescription": derivationDescription, "derivationId": derivationId, "value": value, "foodNutrientSourceId": foodNutrientSourceId, "foodNutrientSourceCode": foodNutrientSourceCode, "foodNutrientSourceDescription": foodNutrientSourceDescriptionValues .reverse[foodNutrientSourceDescription], "rank": rank, "indentLevel": indentLevel, "foodNutrientId": foodNutrientId, "dataPoints": dataPoints, "min": min, "max": max, "median": median, }; } enum DerivationCode { A, AS, BFFN, BFNN, BFZN, CAZN, LC, NC, NR, T, Z } final derivationCodeValues = EnumValues({ "A": DerivationCode.A, "AS": DerivationCode.AS, "BFFN": DerivationCode.BFFN, "BFNN": DerivationCode.BFNN, "BFZN": DerivationCode.BFZN, "CAZN": DerivationCode.CAZN, "LC": DerivationCode.LC, "NC": DerivationCode.NC, "NR": DerivationCode.NR, "T": DerivationCode.T, "Z": DerivationCode.Z }); enum FoodNutrientSourceDescription { ANALYTICAL_OR_DERIVED_FROM_ANALYTICAL, ASSUMED_ZERO, CALCULATED_FROM_NUTRIENT_LABEL_BY_NDL, CALCULATED_OR_IMPUTED } final foodNutrientSourceDescriptionValues = EnumValues({ "Analytical or derived from analytical": FoodNutrientSourceDescription.ANALYTICAL_OR_DERIVED_FROM_ANALYTICAL, "Assumed zero": FoodNutrientSourceDescription.ASSUMED_ZERO, "Calculated from nutrient label by NDL": FoodNutrientSourceDescription.CALCULATED_FROM_NUTRIENT_LABEL_BY_NDL, "Calculated or imputed": FoodNutrientSourceDescription.CALCULATED_OR_IMPUTED }); enum UnitName { G, IU, KCAL, K_J, MG, UG } final unitNameValues = EnumValues({ "G": UnitName.G, "IU": UnitName.IU, "KCAL": UnitName.KCAL, "kJ": UnitName.K_J, "MG": UnitName.MG, "UG": UnitName.UG }); class EnumValues { Map map; late Map reverseMap; EnumValues(this.map); Map get reverse { reverseMap = map.map((k, v) => MapEntry(v, k)); return reverseMap; } }