{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schemas.bakery-ia.com/demo/recipes/recipe_ingredient/v1",
  "type": "object",
  "title": "RecipeIngredient",
  "description": "Ingredient required for a recipe",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "Unique recipe ingredient identifier"
    },
    "tenant_id": {
      "type": "string",
      "format": "uuid",
      "description": "Tenant owner (replaced during cloning)"
    },
    "recipe_id": {
      "type": "string",
      "format": "uuid",
      "description": "Reference to recipes.Recipe"
    },
    "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "description": "Cross-service ref to inventory.Ingredient"
    },
    "quantity": {
      "type": "number",
      "minimum": 0.001
    },
    "unit": {
      "type": "string",
      "enum": ["g", "kg", "ml", "l", "cups", "tbsp", "tsp", "units", "pieces", "%"]
    },
    "quantity_in_base_unit": {
      "type": ["number", "null"],
      "minimum": 0
    },
    "alternative_quantity": {
      "type": ["number", "null"],
      "minimum": 0
    },
    "alternative_unit": {
      "type": ["string", "null"],
      "enum": ["g", "kg", "ml", "l", "cups", "tbsp", "tsp", "units", "pieces", "%"]
    },
    "preparation_method": {
      "type": ["string", "null"],
      "maxLength": 255
    },
    "ingredient_notes": {
      "type": ["string", "null"]
    },
    "is_optional": {
      "type": "boolean",
      "default": false
    },
    "ingredient_order": {
      "type": "integer",
      "minimum": 1,
      "default": 1
    },
    "ingredient_group": {
      "type": ["string", "null"],
      "maxLength": 100
    },
    "substitution_options": {
      "type": ["array", "null"],
      "items": {
        "type": "object",
        "properties": {
          "ingredient_id": {"type": "string", "format": "uuid"},
          "name": {"type": "string"},
          "ratio": {"type": "number"}
        }
      }
    },
    "substitution_ratio": {
      "type": ["number", "null"],
      "minimum": 0.1
    },
    "unit_cost": {
      "type": ["number", "null"],
      "minimum": 0
    },
    "total_cost": {
      "type": ["number", "null"],
      "minimum": 0
    },
    "cost_updated_at": {
      "type": ["string", "null"],
      "format": "date-time"
    }
  },
  "required": [
    "id", "tenant_id", "recipe_id", "ingredient_id", "quantity", "unit", "ingredient_order"
  ],
  "additionalProperties": false
}