{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Seefood menu checkpoint 0.2.0 (legacy 0.1.0 accepted)",
  "type": "object",
  "required": [
    "schema_version",
    "restaurant",
    "mode",
    "dishes"
  ],
  "properties": {
    "schema_version": {
      "enum": [
        "0.1.0",
        "0.2.0"
      ]
    },
    "restaurant": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "branch": {
          "type": [
            "string",
            "null"
          ]
        },
        "source_page_url": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "mode": {
      "enum": [
        "quick",
        "deep"
      ]
    },
    "context": {
      "type": "object"
    },
    "dishes": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "name",
          "image",
          "reviews",
          "allergens"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "price": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0
          },
          "currency": {
            "type": [
              "string",
              "null"
            ]
          },
          "source_page_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "image": {
            "type": "object",
            "required": [
              "kind",
              "url",
              "match_status"
            ],
            "properties": {
              "kind": {
                "enum": [
                  "source_photo",
                  "video_thumbnail",
                  "ai_generated",
                  "none",
                  "search_thumbnail"
                ]
              },
              "url": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uri"
              },
              "source_page_url": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "caption": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "photographer": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "date_label": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "match_status": {
                "enum": [
                  "confirmed",
                  "unconfirmed",
                  "generated",
                  "missing"
                ]
              },
              "reference_notes": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "evidence_status": {
                "enum": [
                  "observed",
                  "muse_reported",
                  "unverified"
                ]
              },
              "match_evidence": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "allOf": [
              {
                "if": {
                  "properties": {
                    "kind": {
                      "const": "none"
                    }
                  }
                },
                "then": {
                  "properties": {
                    "url": {
                      "type": "null"
                    },
                    "match_status": {
                      "const": "missing"
                    }
                  }
                }
              },
              {
                "if": {
                  "properties": {
                    "kind": {
                      "const": "ai_generated"
                    }
                  }
                },
                "then": {
                  "required": [
                    "caption"
                  ],
                  "properties": {
                    "caption": {
                      "type": "string",
                      "minLength": 1
                    },
                    "match_status": {
                      "const": "generated"
                    }
                  }
                }
              },
              {
                "if": {
                  "properties": {
                    "kind": {
                      "enum": [
                        "source_photo",
                        "video_thumbnail",
                        "search_thumbnail"
                      ]
                    }
                  }
                },
                "then": {
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "match_status": {
                      "enum": [
                        "confirmed",
                        "unconfirmed"
                      ]
                    }
                  }
                }
              }
            ]
          },
          "reviews": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "summary",
                "source_page_url",
                "evidence_status"
              ],
              "properties": {
                "reviewer": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "summary": {
                  "type": "string"
                },
                "source_page_url": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "date_label": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "evidence_status": {
                  "enum": [
                    "observed",
                    "muse_reported",
                    "excerpt_only",
                    "blocked"
                  ]
                }
              }
            }
          },
          "allergens": {
            "type": "object",
            "required": [
              "status",
              "items"
            ],
            "properties": {
              "status": {
                "enum": [
                  "unconfirmed",
                  "restaurant_confirmed"
                ]
              },
              "items": {
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "string"
                }
              },
              "source_page_url": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "calories": {
            "type": "object",
            "properties": {
              "value": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "status": {
                "enum": [
                  "unknown",
                  "estimated",
                  "published"
                ]
              },
              "source_page_url": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "cultural_context": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "text",
                "evidence_status"
              ],
              "properties": {
                "text": {
                  "type": "string"
                },
                "source_page_url": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "evidence_status": {
                  "enum": [
                    "sourced",
                    "general_knowledge",
                    "unverified"
                  ]
                }
              }
            }
          },
          "menu_item_id": {
            "type": "string",
            "minLength": 1
          },
          "section": {
            "type": "string"
          },
          "source_order": {
            "type": "integer",
            "minimum": 0
          },
          "modifiers": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "translated_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "pairings": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "text",
                "kind",
                "availability",
                "source_page_url"
              ],
              "properties": {
                "text": {
                  "type": "string",
                  "minLength": 1
                },
                "kind": {
                  "enum": [
                    "wine",
                    "beer",
                    "cocktail",
                    "non_alcoholic",
                    "other"
                  ]
                },
                "availability": {
                  "enum": [
                    "restaurant_listed",
                    "unconfirmed_idea"
                  ]
                },
                "source_page_url": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uri"
                },
                "price": {
                  "type": [
                    "number",
                    "null"
                  ],
                  "minimum": 0
                },
                "currency": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "allOf": [
                {
                  "if": {
                    "properties": {
                      "availability": {
                        "const": "restaurant_listed"
                      }
                    }
                  },
                  "then": {
                    "properties": {
                      "source_page_url": {
                        "type": "string",
                        "format": "uri"
                      }
                    }
                  }
                }
              ]
            }
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "image": {
                  "properties": {
                    "kind": {
                      "enum": [
                        "source_photo",
                        "video_thumbnail",
                        "search_thumbnail"
                      ]
                    }
                  }
                }
              }
            },
            "then": {
              "properties": {
                "image": {
                  "required": [
                    "source_page_url"
                  ],
                  "properties": {
                    "source_page_url": {
                      "type": "string",
                      "format": "uri"
                    }
                  }
                }
              }
            }
          }
        ]
      }
    },
    "metrics": {
      "type": "object",
      "properties": {
        "elapsed_seconds": {
          "type": [
            "number",
            "null"
          ]
        },
        "timing_scope": {
          "type": [
            "string",
            "null"
          ]
        },
        "browser_actions": {
          "type": [
            "integer",
            "null"
          ]
        },
        "orchestration_calls": {
          "type": [
            "integer",
            "null"
          ]
        }
      }
    },
    "official_menu": {
      "type": "object",
      "required": [
        "source_page_url",
        "retrieved_at",
        "completeness",
        "items"
      ],
      "properties": {
        "source_page_url": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "retrieved_at": {
          "type": "string",
          "format": "date-time"
        },
        "stated_menu_date": {
          "type": [
            "string",
            "null"
          ]
        },
        "meal_service": {
          "type": [
            "string",
            "null"
          ]
        },
        "source_kind": {
          "enum": [
            "official",
            "user_photo",
            "third_party_provisional"
          ]
        },
        "completeness": {
          "enum": [
            "complete",
            "partial",
            "unknown"
          ]
        },
        "gaps": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "items": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "menu_item_id",
              "name",
              "section",
              "source_order"
            ],
            "properties": {
              "menu_item_id": {
                "type": "string",
                "minLength": 1
              },
              "name": {
                "type": "string",
                "minLength": 1
              },
              "section": {
                "type": "string"
              },
              "source_order": {
                "type": "integer",
                "minimum": 0
              },
              "description": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "modifiers": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "recommendations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "menu_item_ids",
          "reason",
          "basis"
        ],
        "properties": {
          "menu_item_ids": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": {
              "type": "string"
            }
          },
          "reason": {
            "type": "string",
            "minLength": 1
          },
          "basis": {
            "type": "array",
            "minItems": 1,
            "items": {
              "enum": [
                "preferences",
                "dietary_constraints",
                "budget",
                "occasion",
                "group_balance",
                "reviews",
                "season",
                "weather",
                "pairing"
              ]
            }
          },
          "source_page_urls": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          }
        }
      }
    },
    "weather": {
      "type": [
        "object",
        "null"
      ],
      "required": [
        "status",
        "location",
        "source_page_url"
      ],
      "properties": {
        "status": {
          "enum": [
            "forecast",
            "observed",
            "seasonal_only",
            "unknown"
          ]
        },
        "location": {
          "type": "string"
        },
        "source_page_url": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "retrieved_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "valid_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "temperature_c": {
          "type": [
            "number",
            "null"
          ]
        },
        "summary": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "enum": [
                  "forecast",
                  "observed"
                ]
              }
            }
          },
          "then": {
            "required": [
              "retrieved_at",
              "valid_at"
            ],
            "properties": {
              "source_page_url": {
                "type": "string",
                "format": "uri"
              },
              "retrieved_at": {
                "type": "string",
                "format": "date-time"
              },
              "valid_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "status": {
                "enum": [
                  "seasonal_only",
                  "unknown"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "temperature_c": {
                "type": "null"
              }
            }
          }
        }
      ]
    },
    "off_menu_findings": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "name",
          "source_page_url",
          "availability_note"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "source_page_url": {
            "type": "string",
            "format": "uri"
          },
          "availability_note": {
            "type": "string"
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "schema_version": {
            "const": "0.2.0"
          }
        }
      },
      "then": {
        "required": [
          "official_menu"
        ],
        "properties": {
          "dishes": {
            "items": {
              "required": [
                "menu_item_id",
                "section",
                "source_order"
              ]
            }
          }
        }
      }
    }
  ]
}
