{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.mildport.com/spec/import-receipt.v1.schema.json",
  "title": "Mildport Signed Import Receipt v1",
  "description": "The portable evidence artifact issued when an import is applied: the plain receipt document (per-value lineage from source identity through every recorded decision to the delivered outcome) plus a detached JWS over its canonical JSON form. Verifies offline — no Mildport service in the loop.",
  "$comment": "License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Generated from the Mildport contract sources — do not edit by hand.",
  "type": "object",
  "properties": {
    "receipt": {
      "type": "object",
      "properties": {
        "receiptVersion": {
          "type": "number",
          "const": 1
        },
        "receiptId": {
          "type": "string",
          "pattern": "^rcpt_[A-Za-z0-9_-]{8,64}$"
        },
        "recordId": {
          "type": "string"
        },
        "tenantId": {
          "type": "string"
        },
        "source": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "detected": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "format": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "externalId": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "envelopeId": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "pageCount": {
                  "anyOf": [
                    {
                      "type": "number"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "sheets": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "rowCount": {
                        "type": "number"
                      },
                      "columnCount": {
                        "type": "number"
                      }
                    },
                    "required": [
                      "name",
                      "rowCount",
                      "columnCount"
                    ],
                    "additionalProperties": false
                  }
                }
              },
              "required": [
                "detected",
                "format",
                "externalId",
                "envelopeId",
                "pageCount",
                "sheets"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        },
        "decisions": {
          "type": "object",
          "properties": {
            "questionCounts": {
              "type": "object",
              "propertyNames": {
                "type": "string",
                "enum": [
                  "open",
                  "answered",
                  "dismissed",
                  "superseded"
                ]
              },
              "additionalProperties": {
                "type": "number"
              },
              "required": [
                "open",
                "answered",
                "dismissed",
                "superseded"
              ]
            },
            "mapping": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "header": {
                    "type": "string"
                  },
                  "columnKey": {
                    "type": "string"
                  },
                  "actor": {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "enum": [
                          "human",
                          "agent"
                        ]
                      },
                      "id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 200
                      }
                    },
                    "required": [
                      "kind"
                    ],
                    "additionalProperties": false
                  },
                  "answeredAt": {
                    "type": "string"
                  }
                },
                "required": [
                  "header",
                  "columnKey",
                  "actor",
                  "answeredAt"
                ],
                "additionalProperties": false
              }
            },
            "references": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "field": {
                    "type": "string"
                  },
                  "entity": {
                    "type": "string"
                  },
                  "targetId": {
                    "type": "string"
                  },
                  "rows": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "actor": {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "enum": [
                          "human",
                          "agent"
                        ]
                      },
                      "id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 200
                      }
                    },
                    "required": [
                      "kind"
                    ],
                    "additionalProperties": false
                  },
                  "answeredAt": {
                    "type": "string"
                  }
                },
                "required": [
                  "field",
                  "targetId",
                  "rows",
                  "actor",
                  "answeredAt"
                ],
                "additionalProperties": false
              }
            },
            "ledger": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "identity": {
                    "type": "string"
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "mapping",
                      "reference",
                      "validation",
                      "fact"
                    ]
                  },
                  "subject": {
                    "type": "object",
                    "properties": {
                      "header": {
                        "type": "string"
                      },
                      "columnKey": {
                        "type": "string"
                      },
                      "entity": {
                        "type": "string"
                      },
                      "field": {
                        "type": "string"
                      },
                      "rule": {
                        "type": "string"
                      },
                      "factId": {
                        "type": "string"
                      },
                      "rowCount": {
                        "type": "number"
                      },
                      "rowRefs": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    },
                    "additionalProperties": false
                  },
                  "promptKey": {
                    "type": "string"
                  },
                  "prompt": {
                    "type": "string"
                  },
                  "evidence": {
                    "type": "object",
                    "properties": {
                      "reasonCodes": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      "samples": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      "candidates": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "value": {
                              "type": "string"
                            },
                            "label": {
                              "type": "string"
                            },
                            "confidence": {
                              "type": "number"
                            },
                            "probability": {
                              "type": "number",
                              "minimum": 0,
                              "maximum": 1
                            },
                            "factorKeys": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              }
                            },
                            "confidenceFactors": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "key": {
                                    "type": "string"
                                  },
                                  "llr": {
                                    "type": "number"
                                  }
                                },
                                "required": [
                                  "key",
                                  "llr"
                                ],
                                "additionalProperties": false
                              }
                            },
                            "reasonCodes": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              }
                            }
                          },
                          "required": [
                            "value"
                          ],
                          "additionalProperties": false
                        }
                      },
                      "blockFields": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "header": {
                              "type": "string"
                            },
                            "keyByCandidate": {
                              "type": "object",
                              "propertyNames": {
                                "type": "string"
                              },
                              "additionalProperties": {
                                "type": "string"
                              }
                            }
                          },
                          "required": [
                            "header",
                            "keyByCandidate"
                          ],
                          "additionalProperties": false
                        }
                      }
                    },
                    "required": [
                      "candidates"
                    ],
                    "additionalProperties": false
                  },
                  "cost": {
                    "type": "string",
                    "enum": [
                      "low",
                      "medium",
                      "high"
                    ]
                  },
                  "evidenceFingerprint": {
                    "type": "string"
                  },
                  "id": {
                    "type": "string"
                  },
                  "recordId": {
                    "type": "string"
                  },
                  "state": {
                    "type": "string",
                    "enum": [
                      "open",
                      "answered",
                      "dismissed",
                      "superseded"
                    ]
                  },
                  "generation": {
                    "type": "number"
                  },
                  "answer": {
                    "type": "object",
                    "properties": {
                      "value": {
                        "type": "string"
                      },
                      "actor": {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "enum": [
                              "human",
                              "agent"
                            ]
                          },
                          "id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 200
                          }
                        },
                        "required": [
                          "kind"
                        ],
                        "additionalProperties": false
                      },
                      "grounding": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      "answeredAt": {
                        "type": "string"
                      },
                      "meta": {
                        "type": "object",
                        "properties": {
                          "keptDefault": {
                            "type": "boolean"
                          }
                        },
                        "required": [
                          "keptDefault"
                        ],
                        "additionalProperties": false
                      }
                    },
                    "required": [
                      "value",
                      "actor",
                      "answeredAt"
                    ],
                    "additionalProperties": false
                  },
                  "dismissedBy": {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "enum": [
                          "human",
                          "agent"
                        ]
                      },
                      "id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 200
                      }
                    },
                    "required": [
                      "kind"
                    ],
                    "additionalProperties": false
                  },
                  "dismissReason": {
                    "type": "string"
                  },
                  "supersededReason": {
                    "type": "string",
                    "const": "resolved-in-flow"
                  },
                  "createdAt": {
                    "type": "string"
                  },
                  "updatedAt": {
                    "type": "string"
                  }
                },
                "required": [
                  "identity",
                  "kind",
                  "subject",
                  "promptKey",
                  "prompt",
                  "evidence",
                  "cost",
                  "evidenceFingerprint",
                  "id",
                  "recordId",
                  "state",
                  "generation",
                  "createdAt",
                  "updatedAt"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "questionCounts",
            "mapping",
            "references",
            "ledger"
          ],
          "additionalProperties": false
        },
        "outcome": {
          "type": "object",
          "properties": {
            "action": {
              "type": "string",
              "enum": [
                "submit",
                "discard"
              ]
            },
            "rowCount": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "deliveries": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "deliveryId": {
                    "type": "string"
                  },
                  "event": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string"
                  },
                  "rowCount": {
                    "type": "number"
                  },
                  "at": {
                    "type": "string"
                  }
                },
                "required": [
                  "deliveryId",
                  "event",
                  "status",
                  "rowCount",
                  "at"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "action",
            "rowCount",
            "deliveries"
          ],
          "additionalProperties": false
        },
        "issuedAt": {
          "type": "string"
        },
        "calibration": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "keyId": {
              "type": "string"
            }
          },
          "required": [
            "id"
          ],
          "additionalProperties": false
        },
        "transforms": {
          "type": "array",
          "items": {}
        },
        "facts": {
          "type": "array",
          "items": {}
        },
        "validation": {},
        "changesetId": {
          "type": "string"
        },
        "certificate": {
          "type": "object",
          "properties": {
            "population": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "sampled": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "defectsFound": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "defectRateUpperBound": {
              "type": "number",
              "minimum": 0,
              "maximum": 1
            },
            "confidence": {
              "type": "number",
              "exclusiveMinimum": 0,
              "exclusiveMaximum": 1
            },
            "method": {
              "type": "string",
              "const": "clopper-pearson"
            },
            "strata": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "population": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  },
                  "weight": {
                    "type": "number",
                    "minimum": 1
                  },
                  "sampleSize": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  },
                  "defectsFound": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  }
                },
                "required": [
                  "name",
                  "population",
                  "weight",
                  "sampleSize",
                  "defectsFound"
                ],
                "additionalProperties": false
              }
            },
            "seed": {
              "type": "string"
            }
          },
          "required": [
            "population",
            "sampled",
            "defectsFound",
            "defectRateUpperBound",
            "confidence",
            "method",
            "strata",
            "seed"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "receiptVersion",
        "receiptId",
        "recordId",
        "tenantId",
        "source",
        "decisions",
        "outcome",
        "issuedAt"
      ],
      "additionalProperties": false
    },
    "signature": {
      "type": "object",
      "properties": {
        "protected": {
          "type": "string"
        },
        "signature": {
          "type": "string"
        }
      },
      "required": [
        "protected",
        "signature"
      ],
      "additionalProperties": false
    },
    "keyId": {
      "type": "string"
    }
  },
  "required": [
    "receipt",
    "signature",
    "keyId"
  ],
  "additionalProperties": false
}
