{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.local/plano-dieta-variada.schema.v3.4.json",
  "title": "Plano de dieta variada — schema 3.4 com pesos operacionais crus e preparo detalhado",
  "type": "object",
  "required": [
    "schema_version",
    "generated_at",
    "language",
    "source_artifact",
    "goals_and_constraints",
    "methodology",
    "targets",
    "ingredients",
    "seasonings_and_sauces",
    "sources",
    "recipe_library",
    "meal_options",
    "daily_plans",
    "validation",
    "preparation_methodology",
    "preparation_method_library",
    "preparation_update_summary",
    "raw_weight_methodology",
    "raw_weight_update_summary"
  ],
  "properties": {
    "schema_version": {
      "const": "3.4.0"
    },
    "generated_at": {
      "type": "string",
      "format": "date-time"
    },
    "language": {
      "type": "string",
      "const": "pt-BR"
    },
    "source_artifact": {
      "type": "object",
      "required": [
        "filename",
        "note"
      ],
      "properties": {
        "filename": {
          "type": "string"
        },
        "note": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "goals_and_constraints": {
      "type": "object",
      "required": [
        "primary_goal",
        "lactose",
        "excluded_ingredients",
        "macro_priority",
        "culinary_rule"
      ],
      "properties": {
        "primary_goal": {
          "type": "string"
        },
        "lactose": {
          "type": "string"
        },
        "excluded_ingredients": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "macro_priority": {
          "type": "string"
        },
        "culinary_rule": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "methodology": {
      "type": "object",
      "required": [
        "nutrition",
        "calculation",
        "trace_ingredients",
        "sweet_breakfast_note",
        "not_medical_advice"
      ],
      "properties": {
        "nutrition": {
          "type": "string"
        },
        "calculation": {
          "type": "string"
        },
        "trace_ingredients": {
          "type": "string"
        },
        "sweet_breakfast_note": {
          "type": "string"
        },
        "not_medical_advice": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "targets": {
      "type": "object",
      "required": [
        "breakfast",
        "lunch",
        "afternoon_snack_sweet",
        "afternoon_snack_savory",
        "dinner"
      ],
      "properties": {
        "breakfast": {
          "$ref": "#/$defs/target"
        },
        "lunch": {
          "$ref": "#/$defs/target"
        },
        "afternoon_snack_sweet": {
          "$ref": "#/$defs/target"
        },
        "afternoon_snack_savory": {
          "$ref": "#/$defs/target"
        },
        "dinner": {
          "$ref": "#/$defs/target"
        }
      },
      "additionalProperties": false
    },
    "ingredients": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/ingredient"
      }
    },
    "seasonings_and_sauces": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/seasoning"
      }
    },
    "sources": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/source"
      }
    },
    "recipe_library": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/recipe"
      }
    },
    "meal_options": {
      "type": "object",
      "required": [
        "breakfast",
        "lunch",
        "afternoon_snack_sweet",
        "afternoon_snack_savory",
        "dinner"
      ],
      "properties": {
        "breakfast": {
          "type": "array",
          "minItems": 150,
          "maxItems": 150,
          "items": {
            "$ref": "#/$defs/meal_option"
          }
        },
        "lunch": {
          "type": "array",
          "minItems": 150,
          "maxItems": 150,
          "items": {
            "$ref": "#/$defs/meal_option"
          }
        },
        "afternoon_snack_sweet": {
          "type": "array",
          "minItems": 75,
          "maxItems": 75,
          "items": {
            "$ref": "#/$defs/meal_option"
          }
        },
        "afternoon_snack_savory": {
          "type": "array",
          "minItems": 75,
          "maxItems": 75,
          "items": {
            "$ref": "#/$defs/meal_option"
          }
        },
        "dinner": {
          "type": "array",
          "minItems": 150,
          "maxItems": 150,
          "items": {
            "$ref": "#/$defs/meal_option"
          }
        }
      },
      "additionalProperties": false
    },
    "daily_plans": {
      "type": "array",
      "minItems": 150,
      "maxItems": 150,
      "items": {
        "$ref": "#/$defs/daily_plan"
      }
    },
    "validation": {
      "type": "object"
    },
    "preparation_methodology": {
      "type": "object",
      "additionalProperties": true
    },
    "preparation_method_library": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/preparation_method"
      }
    },
    "preparation_update_summary": {
      "type": "object",
      "additionalProperties": true
    },
    "raw_weight_methodology": {
      "type": "object",
      "additionalProperties": true
    },
    "raw_weight_update_summary": {
      "type": "object",
      "additionalProperties": true
    }
  },
  "$defs": {
    "macro": {
      "type": "object",
      "required": [
        "kcal",
        "protein_g",
        "carbs_g",
        "fat_g"
      ],
      "properties": {
        "kcal": {
          "type": "number"
        },
        "protein_g": {
          "type": "number"
        },
        "carbs_g": {
          "type": "number"
        },
        "fat_g": {
          "type": "number"
        }
      },
      "additionalProperties": false
    },
    "target": {
      "type": "object",
      "required": [
        "label",
        "kcal",
        "protein_g",
        "carbs_g",
        "fat_g"
      ],
      "properties": {
        "label": {
          "type": "string"
        },
        "kcal": {
          "type": "number"
        },
        "protein_g": {
          "type": "number"
        },
        "carbs_g": {
          "type": "number"
        },
        "fat_g": {
          "type": "number"
        }
      },
      "additionalProperties": false
    },
    "source": {
      "type": "object",
      "required": [
        "id",
        "title",
        "url",
        "site",
        "kind",
        "rating",
        "rating_count",
        "notes"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "site": {
          "type": [
            "string",
            "null"
          ]
        },
        "kind": {
          "type": "string"
        },
        "rating": {
          "type": [
            "number",
            "null"
          ]
        },
        "rating_count": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "notes": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "additionalProperties": false
    },
    "ingredient": {
      "type": "object",
      "required": [
        "id",
        "name",
        "measurement_state",
        "nutrition_reference",
        "yield_to_nutrition_reference",
        "notes"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "measurement_state": {
          "type": "string",
          "enum": [
            "raw_ready_to_cook",
            "raw_ready_to_use",
            "as_purchased_ready_to_use"
          ]
        },
        "nutrition_reference": {
          "type": "object",
          "required": [
            "state_name",
            "per_100g",
            "source_id",
            "note"
          ],
          "properties": {
            "state_name": {
              "type": "string"
            },
            "per_100g": {
              "$ref": "#/$defs/macro"
            },
            "source_id": {
              "type": [
                "string",
                "null"
              ]
            },
            "note": {
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "yield_to_nutrition_reference": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "required": [
                "default_factor",
                "source_id",
                "quality",
                "basis",
                "formula"
              ],
              "properties": {
                "default_factor": {
                  "type": "number",
                  "exclusiveMinimum": 0
                },
                "source_id": {
                  "type": "string"
                },
                "quality": {
                  "type": "string"
                },
                "basis": {
                  "type": "string"
                },
                "formula": {
                  "type": "string"
                }
              },
              "additionalProperties": false
            }
          ]
        },
        "notes": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "additionalProperties": false
    },
    "seasoning": {
      "type": "object",
      "required": [
        "id",
        "name",
        "flavor_profile",
        "best_uses",
        "lactose_macro_note",
        "source_ids",
        "rating_note"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "flavor_profile": {
          "type": "string"
        },
        "best_uses": {
          "type": "string"
        },
        "lactose_macro_note": {
          "type": "string"
        },
        "source_ids": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1,
          "uniqueItems": true,
          "$comment": "Foreign keys into /sources."
        },
        "rating_note": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "additionalProperties": false
    },
    "source_quality": {
      "type": "object",
      "required": [
        "has_source",
        "source_count",
        "rated_source_count",
        "best_rating",
        "best_rating_count",
        "rating_status"
      ],
      "properties": {
        "has_source": {
          "type": "boolean"
        },
        "source_count": {
          "type": "integer",
          "minimum": 0
        },
        "rated_source_count": {
          "type": "integer",
          "minimum": 0
        },
        "best_rating": {
          "type": [
            "number",
            "null"
          ]
        },
        "best_rating_count": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0
        },
        "rating_status": {
          "type": "string",
          "enum": [
            "rated_source_available",
            "no_numeric_rating_on_referenced_source"
          ]
        }
      },
      "additionalProperties": false
    },
    "recipe": {
      "type": "object",
      "required": [
        "id",
        "name",
        "category",
        "origin",
        "method_overview",
        "seasoning_text",
        "seasoning_refs",
        "source_ids",
        "adaptation_notes",
        "trace_ingredients",
        "source_quality",
        "preparation"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "category": {
          "type": "string"
        },
        "origin": {
          "type": "string"
        },
        "method_overview": {
          "type": "string"
        },
        "seasoning_text": {
          "type": [
            "string",
            "null"
          ]
        },
        "seasoning_refs": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true,
          "$comment": "Foreign keys into /seasonings_and_sauces."
        },
        "source_ids": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1,
          "uniqueItems": true,
          "$comment": "Foreign keys into /sources."
        },
        "adaptation_notes": {
          "type": "string"
        },
        "trace_ingredients": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "source_quality": {
          "$ref": "#/$defs/source_quality"
        },
        "preparation": {
          "$ref": "#/$defs/recipe_preparation"
        }
      },
      "additionalProperties": false
    },
    "ingredient_line": {
      "type": "object",
      "required": [
        "ingredient_id",
        "ingredient_name",
        "grams",
        "measurement_state",
        "nutrition_basis_grams",
        "yield_conversion",
        "macros"
      ],
      "properties": {
        "ingredient_id": {
          "type": "string"
        },
        "ingredient_name": {
          "type": "string"
        },
        "grams": {
          "type": "number",
          "minimum": 0
        },
        "measurement_state": {
          "type": "string",
          "enum": [
            "raw_ready_to_cook",
            "raw_ready_to_use",
            "as_purchased_ready_to_use"
          ]
        },
        "nutrition_basis_grams": {
          "type": "number",
          "minimum": 0
        },
        "yield_conversion": {
          "anyOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "required": [
                "factor_raw_to_nutrition_basis",
                "expected_nutrition_basis_grams",
                "source_id",
                "quality",
                "basis",
                "formula",
                "planning_note"
              ],
              "properties": {
                "factor_raw_to_nutrition_basis": {
                  "type": "number",
                  "exclusiveMinimum": 0
                },
                "expected_nutrition_basis_grams": {
                  "type": "number",
                  "minimum": 0
                },
                "source_id": {
                  "type": "string"
                },
                "quality": {
                  "type": "string"
                },
                "basis": {
                  "type": "string"
                },
                "formula": {
                  "type": "string"
                },
                "planning_note": {
                  "type": "string"
                }
              },
              "additionalProperties": false
            }
          ]
        },
        "macros": {
          "$ref": "#/$defs/macro"
        }
      },
      "additionalProperties": false
    },
    "portion": {
      "type": "object",
      "required": [
        "ingredients",
        "total"
      ],
      "properties": {
        "ingredients": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/ingredient_line"
          }
        },
        "total": {
          "$ref": "#/$defs/macro"
        }
      },
      "additionalProperties": false
    },
    "recipe_use": {
      "type": "object",
      "required": [
        "recipe_id",
        "portion"
      ],
      "properties": {
        "recipe_id": {
          "type": "string",
          "$comment": "Foreign key into /recipe_library."
        },
        "portion": {
          "$ref": "#/$defs/portion"
        }
      },
      "additionalProperties": false
    },
    "meal_option": {
      "type": "object",
      "required": [
        "id",
        "name",
        "recipe_uses",
        "total",
        "delta_vs_target",
        "origin"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "recipe_uses": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/recipe_use"
          }
        },
        "total": {
          "$ref": "#/$defs/macro"
        },
        "delta_vs_target": {
          "$ref": "#/$defs/macro"
        },
        "origin": {
          "type": "string"
        },
        "sweet": {
          "type": "boolean"
        },
        "macro_note": {
          "type": "string"
        },
        "pairing_basis": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "daily_plan": {
      "type": "object",
      "required": [
        "id",
        "breakfast_option_id",
        "lunch_option_id",
        "snack_type",
        "snack_option_id",
        "dinner_option_id",
        "total",
        "delta_vs_corresponding_daily_target"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "breakfast_option_id": {
          "type": "string"
        },
        "lunch_option_id": {
          "type": "string"
        },
        "snack_type": {
          "type": "string",
          "enum": [
            "sweet",
            "savory"
          ]
        },
        "snack_option_id": {
          "type": "string"
        },
        "dinner_option_id": {
          "type": "string"
        },
        "total": {
          "$ref": "#/$defs/macro"
        },
        "delta_vs_corresponding_daily_target": {
          "$ref": "#/$defs/macro"
        }
      },
      "additionalProperties": false
    },
    "preparation_method": {
      "type": "object",
      "required": [
        "id",
        "source_id",
        "source_title",
        "source_url",
        "extraction_status",
        "equipment",
        "source_method_paraphrase",
        "adaptation_guardrails"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "source_id": {
          "type": "string"
        },
        "source_title": {
          "type": [
            "string",
            "null"
          ]
        },
        "source_url": {
          "type": [
            "string",
            "null"
          ]
        },
        "extraction_status": {
          "type": "string"
        },
        "equipment": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "source_method_paraphrase": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "source_time_reference": {
          "type": [
            "string",
            "null"
          ]
        },
        "source_temperature_reference": {
          "type": [
            "string",
            "null"
          ]
        },
        "source_endpoint_reference": {
          "type": [
            "string",
            "null"
          ]
        },
        "adaptation_guardrails": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "copyright_note": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "preparation_step": {
      "type": "object",
      "required": [
        "order",
        "instruction"
      ],
      "properties": {
        "order": {
          "type": "integer",
          "minimum": 1
        },
        "instruction": {
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "preparation_component": {
      "type": "object",
      "required": [
        "name",
        "source_method_ids",
        "grounding_level",
        "equipment",
        "steps",
        "source_time_reference",
        "source_temperature_reference",
        "texture_or_doneness_endpoint",
        "adaptation_guardrails"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "source_method_ids": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "grounding_level": {
          "type": "string"
        },
        "equipment": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "steps": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/preparation_step"
          }
        },
        "source_time_reference": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "source_temperature_reference": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "texture_or_doneness_endpoint": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "adaptation_guardrails": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "recipe_preparation": {
      "type": "object",
      "required": [
        "version",
        "detail_level",
        "portioning_note",
        "ingredient_authority",
        "weight_basis",
        "components",
        "assembly_and_storage_notes",
        "adaptation_application",
        "original_method_overview",
        "source_method_coverage"
      ],
      "properties": {
        "version": {
          "type": "string"
        },
        "detail_level": {
          "type": "string"
        },
        "portioning_note": {
          "type": "string"
        },
        "ingredient_authority": {
          "type": "string"
        },
        "weight_basis": {
          "type": "object",
          "required": [
            "primary_measurement_rule",
            "raw_weight_ingredient_ids",
            "as_purchased_weight_ingredient_ids",
            "cooked_weight_ingredient_ids",
            "raw_yield_notes"
          ],
          "properties": {
            "primary_measurement_rule": {
              "type": "string"
            },
            "raw_weight_ingredient_ids": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "as_purchased_weight_ingredient_ids": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "cooked_weight_ingredient_ids": {
              "type": "array",
              "maxItems": 0,
              "items": {
                "type": "string"
              }
            },
            "raw_yield_notes": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "ingredient_id",
                  "raw_state",
                  "yield_factor",
                  "yield_source_id",
                  "quality",
                  "instruction"
                ],
                "properties": {
                  "ingredient_id": {
                    "type": "string"
                  },
                  "raw_state": {
                    "type": "string"
                  },
                  "yield_factor": {
                    "type": "number",
                    "exclusiveMinimum": 0
                  },
                  "yield_source_id": {
                    "type": "string"
                  },
                  "quality": {
                    "type": "string"
                  },
                  "instruction": {
                    "type": "string"
                  }
                },
                "additionalProperties": false
              }
            }
          },
          "additionalProperties": false
        },
        "components": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/preparation_component"
          }
        },
        "assembly_and_storage_notes": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "adaptation_application": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "original_method_overview": {
          "type": "string"
        },
        "source_method_coverage": {
          "type": "object",
          "additionalProperties": true
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}