{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://universalpaper.org/research/schema/0/explanation.schema.json",
  "title": "Explanation (up-research/explanation/0)",
  "description": "An agent's answer to a question about what it did under an agreement: the answer in words, what it cites, and what the agreement leaves open. Every citation can be checked with an engine call that already exists. It adds no Term, Event kind or required field. See https://universalpaper.org/research/cited-explanations/. Research is not part of the Universal Paper language. These formats may change or be withdrawn, and no agreement depends on them.",
  "type": "object",
  "required": [
    "format",
    "spec",
    "asked",
    "answered_by",
    "about",
    "answer",
    "cites",
    "left_open"
  ],
  "additionalProperties": false,
  "properties": {
    "format": {
      "const": "up-research/explanation/0"
    },
    "spec": {
      "type": "string",
      "minLength": 1,
      "description": "The version of the language the agreement is written in."
    },
    "simulated": {
      "type": "boolean"
    },
    "note": {
      "type": "string",
      "minLength": 1
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
    },
    "asked": {
      "type": "string",
      "minLength": 1,
      "description": "The question, in the words of the person who asked it."
    },
    "answered_by": {
      "type": "object",
      "required": [
        "role"
      ],
      "additionalProperties": false,
      "properties": {
        "role": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "agent": {
          "type": "string",
          "pattern": "^ed25519:[0-9a-f]{64}$",
          "description": "The key of the agent that answers."
        },
        "mandate": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$",
          "description": "The content hash of the Mandate the agent acts under."
        }
      }
    },
    "about": {
      "type": "object",
      "required": [
        "chain",
        "fingerprint"
      ],
      "additionalProperties": false,
      "properties": {
        "chain": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$",
          "description": "The ChainId."
        },
        "fingerprint": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$",
          "description": "The content hash of the agreement in force."
        },
        "label": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "action": {
      "type": "object",
      "required": [
        "chain",
        "event",
        "kind",
        "at",
        "accepted"
      ],
      "additionalProperties": false,
      "properties": {
        "chain": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "event": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$",
          "description": "The content hash of the event the question is about."
        },
        "kind": {
          "type": "string",
          "minLength": 1
        },
        "at": {
          "type": "string",
          "format": "date-time"
        },
        "accepted": {
          "type": "boolean",
          "description": "Whether validate_bundle accepts the event."
        }
      }
    },
    "answer": {
      "type": "string",
      "minLength": 1,
      "description": "The answer as the person was given it. It is inside the fingerprint, so the words can be shown later."
    },
    "cites": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "type"
        ],
        "additionalProperties": false,
        "description": "One thing the answer rests on. Each type can be checked with an engine call that already exists.",
        "properties": {
          "type": {
            "enum": [
              "clause",
              "event",
              "mandate",
              "trace"
            ],
            "description": "clause: words of the agreement. event: a signed event on a chain. mandate: a bound in the Mandate of the agent. trace: an engine verdict."
          },
          "chain": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$",
            "description": "The ChainId."
          },
          "agreement": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$",
            "description": "The content hash of the agreement the clause is in."
          },
          "clause": {
            "type": "string",
            "minLength": 1,
            "description": "The name of the clause in that agreement."
          },
          "term": {
            "type": "string",
            "minLength": 1,
            "description": "The Term the clause or the bound belongs to, such as UP:Admin-Fee."
          },
          "quote": {
            "type": "string",
            "minLength": 1,
            "description": "Words copied exactly from the text render_text returns for that clause."
          },
          "event": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$",
            "description": "The content hash of the event."
          },
          "kind": {
            "type": "string",
            "minLength": 1
          },
          "at": {
            "type": "string",
            "format": "date-time"
          },
          "says": {
            "type": "string",
            "minLength": 1,
            "description": "What the event records, in plain words."
          },
          "fingerprint": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$",
            "description": "For a mandate, its content hash. For a trace, the content hash of the trace."
          },
          "param": {
            "type": "string",
            "minLength": 1
          },
          "bound": {
            "type": "object",
            "description": "The bound as the Mandate states it."
          },
          "call": {
            "enum": [
              "validate_bundle",
              "derive_state",
              "check_event",
              "simulate_events",
              "simulate_amendment",
              "simulate_price_conformity",
              "simulate_termination",
              "simulate_eligibility"
            ]
          },
          "url": {
            "type": "string",
            "format": "uri"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "type": {
                  "const": "clause"
                }
              }
            },
            "then": {
              "required": [
                "chain",
                "agreement",
                "clause",
                "term",
                "quote"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "type": {
                  "const": "event"
                }
              }
            },
            "then": {
              "required": [
                "chain",
                "event",
                "kind",
                "at"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "type": {
                  "const": "mandate"
                }
              }
            },
            "then": {
              "required": [
                "fingerprint"
              ]
            }
          },
          {
            "if": {
              "properties": {
                "type": {
                  "const": "trace"
                }
              }
            },
            "then": {
              "required": [
                "fingerprint",
                "call"
              ]
            }
          }
        ]
      },
      "minItems": 1
    },
    "left_open": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "description": "What no citation supports: the parts of the answer the agreement does not decide. Required, and may be empty."
    },
    "sigs": {
      "type": "array",
      "description": "Signatures, in the form the language already uses. Left out of the fingerprint, as everywhere else."
    }
  }
}
