{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hydro-look.vercel.app/api/schema/narrative.schema.json",
  "title": "narrative.json",
  "description": "The day's reading: a paragraph a language model wrote from the payload in `basis` and nothing else, published only when a validator passed it.",
  "type": "object",
  "required": [
    "schema_version",
    "generated_at",
    "data_date",
    "status",
    "model",
    "prompt_version",
    "payload_hash",
    "origin_date",
    "risk_tier",
    "risk_tier_code",
    "risk_tier_source",
    "outlook_es",
    "drivers",
    "confidence",
    "disclaimer",
    "basis",
    "license",
    "attribution",
    "see_also"
  ],
  "properties": {
    "schema_version": {
      "type": "integer",
      "const": 1,
      "description": "The format version. Changes only when a field is removed, renamed or retyped; added fields do not change it."
    },
    "generated_at": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$",
      "description": "When the document was written, UTC."
    },
    "data_date": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
      "description": "The Ecuadorian calendar day the document's readings describe."
    },
    "status": {
      "type": "string",
      "const": "ok"
    },
    "model": {
      "type": "string"
    },
    "prompt_version": {
      "type": "string"
    },
    "payload_hash": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "origin_date": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
      "description": "The day the payload describes; equal to data_date."
    },
    "risk_tier": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "holgado",
        "vigilancia",
        "ajustado",
        "deficit"
      ],
      "description": "The model's Spanish word. Kept in schema_version 1; use the *_code field beside it."
    },
    "risk_tier_code": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "comfortable",
        "watch",
        "tight",
        "deficit"
      ]
    },
    "risk_tier_source": {
      "type": "string",
      "const": "adequacy.current.worst_tier",
      "description": "The adequacy field the tier was copied from."
    },
    "outlook_es": {
      "type": "string"
    },
    "drivers": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "confidence": {
      "type": "string",
      "enum": [
        "low",
        "medium",
        "high"
      ]
    },
    "usage": {
      "type": "object",
      "properties": {
        "input_tokens": {
          "type": [
            "number",
            "null"
          ]
        },
        "output_tokens": {
          "type": [
            "number",
            "null"
          ]
        },
        "cost_usd": {
          "type": [
            "number",
            "null"
          ]
        }
      },
      "required": [
        "input_tokens",
        "output_tokens",
        "cost_usd"
      ]
    },
    "disclaimer": {
      "type": "string"
    },
    "basis": {
      "type": "object",
      "properties": {
        "payload_version": {
          "type": "integer"
        },
        "origin_date": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "reservoirs": {
          "type": "array"
        }
      },
      "required": [
        "payload_version",
        "origin_date",
        "reservoirs"
      ],
      "description": "The payload the text was written from, verbatim."
    },
    "license": {
      "$ref": "#/$defs/license"
    },
    "attribution": {
      "$ref": "#/$defs/attribution"
    },
    "see_also": {
      "$ref": "#/$defs/see_also"
    }
  },
  "$defs": {
    "license": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "const": "MIT"
        },
        "code_url": {
          "type": "string",
          "pattern": "^https?://"
        },
        "data": {
          "type": "string"
        },
        "data_es": {
          "type": "string"
        }
      },
      "required": [
        "code",
        "code_url",
        "data",
        "data_es"
      ]
    },
    "attribution": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "provides": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "pattern": "^https?://"
          },
          "terms": {
            "type": "string"
          },
          "terms_es": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "name",
          "provides",
          "url",
          "terms",
          "terms_es"
        ]
      }
    },
    "see_also": {
      "type": "object",
      "required": [
        "schema",
        "documentation"
      ],
      "description": "Absolute URLs to the other documents, this document's schema and the documentation page.",
      "additionalProperties": {
        "type": "string",
        "pattern": "^https?://"
      }
    },
    "deprecated": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "Fields kept for one more schema version, each with what replaces it."
    }
  }
}
