{
  "type": "object",
  "properties": {
    "schema_version": {
      "const": 1
    },
    "version": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}\\.[0-9]+$"
    },
    "publisher": {
      "type": "string",
      "minLength": 1
    },
    "title": {
      "type": "object",
      "properties": {
        "en": {
          "type": "string",
          "minLength": 1
        },
        "vi": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "en",
        "vi"
      ],
      "additionalProperties": false
    },
    "observation_period": {
      "type": [
        "string",
        "null"
      ]
    },
    "reviewed_at": {
      "type": "string",
      "format": "date"
    },
    "source_snapshot": {
      "type": "string",
      "pattern": "^[a-f0-9]{40}$"
    },
    "source_url": {
      "type": "string",
      "minLength": 1
    },
    "rights": {
      "type": "string",
      "minLength": 1
    },
    "rights_url": {
      "type": "string",
      "format": "uri"
    },
    "release_type": {
      "enum": [
        "documentation",
        "aggregate_data"
      ]
    },
    "data_release": {
      "type": "object",
      "properties": {
        "allowed": {
          "type": "boolean"
        },
        "reason": {
          "type": "string",
          "minLength": 1
        },
        "files": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "url": {
                "type": "string",
                "minLength": 1
              },
              "sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "non_identifying": {
                "const": true
              },
              "source_url": {
                "type": "string",
                "format": "uri"
              },
              "source_version": {
                "type": "string",
                "minLength": 1
              },
              "period": {
                "type": "string",
                "minLength": 1
              },
              "fields": {
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string",
                      "minLength": 1
                    },
                    "permission": {
                      "const": "redistribution_allowed"
                    },
                    "basis_url": {
                      "type": "string",
                      "format": "uri"
                    }
                  },
                  "required": [
                    "name",
                    "permission",
                    "basis_url"
                  ],
                  "additionalProperties": false
                }
              }
            },
            "required": [
              "url",
              "sha256",
              "non_identifying",
              "source_url",
              "source_version",
              "period",
              "fields"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "allowed",
        "reason",
        "files"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "allowed": {
                "const": false
              }
            }
          },
          "then": {
            "properties": {
              "files": {
                "maxItems": 0
              }
            }
          },
          "else": {
            "properties": {
              "files": {
                "minItems": 1
              }
            }
          }
        }
      ]
    },
    "validation": {
      "type": "object",
      "properties": {
        "status": {
          "enum": [
            "withheld_snapshot_not_reproduced",
            "published"
          ]
        },
        "model_sha256": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[a-f0-9]{64}$"
        },
        "data_sha256": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[a-f0-9]{64}$"
        },
        "prediction_log_sha256": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[a-f0-9]{64}$"
        },
        "label_type": {
          "enum": [
            null,
            "asking",
            "adjusted_asking",
            "verified_transaction"
          ]
        },
        "split": {
          "type": [
            "string",
            "null"
          ]
        },
        "n": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1
        },
        "metric": {
          "type": [
            "string",
            "null"
          ]
        },
        "error": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "period": {
          "type": "string",
          "minLength": 1
        },
        "independent_completion_evidence": {
          "type": "boolean"
        }
      },
      "required": [
        "status",
        "model_sha256",
        "data_sha256",
        "prediction_log_sha256",
        "label_type",
        "split",
        "n",
        "metric",
        "error"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "const": "published"
              }
            }
          },
          "then": {
            "required": [
              "period"
            ],
            "properties": {
              "model_sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "data_sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "prediction_log_sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "label_type": {
                "enum": [
                  "asking",
                  "adjusted_asking",
                  "verified_transaction"
                ]
              },
              "split": {
                "type": "string",
                "minLength": 1
              },
              "n": {
                "type": "integer",
                "minimum": 1
              },
              "metric": {
                "type": "string",
                "minLength": 1
              },
              "error": {
                "type": "number",
                "minimum": 0
              }
            }
          },
          "else": {
            "properties": {
              "n": {
                "type": "null"
              },
              "metric": {
                "type": "null"
              },
              "error": {
                "type": "null"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "label_type": {
                "const": "verified_transaction"
              }
            }
          },
          "then": {
            "required": [
              "independent_completion_evidence"
            ],
            "properties": {
              "independent_completion_evidence": {
                "const": true
              }
            }
          }
        }
      ]
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "url": {
            "type": "string",
            "minLength": 1
          },
          "title": {
            "type": "string",
            "minLength": 1
          },
          "publisher": {
            "type": "string",
            "minLength": 1
          },
          "version": {
            "type": "string",
            "minLength": 1
          },
          "reviewed_at": {
            "type": "string",
            "minLength": 1
          },
          "rights": {
            "type": "string",
            "minLength": 1
          },
          "status": {
            "type": "string",
            "minLength": 1
          },
          "vi_url": {
            "type": "string",
            "minLength": 1
          },
          "period": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "url",
          "title",
          "publisher",
          "version",
          "reviewed_at",
          "rights",
          "status",
          "period"
        ],
        "additionalProperties": false
      }
    },
    "provinces": {
      "type": "array",
      "minItems": 13,
      "maxItems": 13,
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "stateLookup": {
            "enum": [
              "partial-residential",
              "not-integrated",
              "integrated-reference"
            ]
          },
          "model": {
            "enum": [
              "asking-based-reference",
              "not-enabled"
            ]
          },
          "modelSha256": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[a-f0-9]{64}$"
          },
          "modelUrl": {
            "type": [
              "string",
              "null"
            ]
          },
          "sourceManifest": {
            "type": [
              "string",
              "null"
            ]
          },
          "lookupUrl": {
            "type": "string",
            "minLength": 1
          },
          "transactionValidation": {
            "const": "not-published"
          }
        },
        "required": [
          "id",
          "name",
          "stateLookup",
          "model",
          "modelSha256",
          "modelUrl",
          "sourceManifest",
          "lookupUrl",
          "transactionValidation"
        ],
        "additionalProperties": false
      }
    },
    "input_hashes": {
      "type": "object",
      "additionalProperties": {
        "type": "string",
        "pattern": "^[a-f0-9]{64}$"
      }
    }
  },
  "required": [
    "schema_version",
    "version",
    "publisher",
    "title",
    "observation_period",
    "reviewed_at",
    "source_snapshot",
    "source_url",
    "rights",
    "rights_url",
    "release_type",
    "data_release",
    "validation",
    "sources",
    "provinces",
    "input_hashes"
  ],
  "additionalProperties": false,
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://vilacgis.com/investor/evidence/manifest.schema.json",
  "title": "Evidence release manifest",
  "allOf": [
    {
      "if": {
        "properties": {
          "data_release": {
            "properties": {
              "allowed": {
                "const": true
              }
            }
          }
        }
      },
      "then": {
        "properties": {
          "release_type": {
            "const": "aggregate_data"
          },
          "observation_period": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    }
  ]
}
