{
  "type": "object",
  "properties": {
    "schema_version": {
      "enum": [
        "0.1.0-draft",
        "1.0.0"
      ]
    },
    "dictionary_version": {
      "type": "string",
      "minLength": 1
    },
    "dataset": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "category": {
          "type": "string",
          "minLength": 1
        },
        "subtype": {
          "type": "string",
          "minLength": 1
        },
        "product": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "category",
        "subtype",
        "product"
      ],
      "additionalProperties": false
    },
    "field": {
      "$ref": "#/$defs/field"
    },
    "claims": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/claim"
      }
    },
    "sources": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/source"
      }
    },
    "applicability": {
      "$ref": "#/$defs/applicability"
    },
    "observations": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "file": {
            "type": "string",
            "minLength": 1
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "data_period": {
            "type": "string",
            "minLength": 1
          },
          "uf": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "field_name": {
            "type": "string",
            "minLength": 1
          },
          "checked_at": {
            "type": "string",
            "format": "date"
          },
          "scope": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "file",
          "url",
          "sha256",
          "data_period",
          "uf",
          "field_name",
          "checked_at",
          "scope"
        ],
        "additionalProperties": false
      }
    },
    "issues": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "status": {
            "enum": [
              "open",
              "resolved"
            ]
          },
          "description": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "id",
          "status",
          "description"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "schema_version",
    "dictionary_version",
    "dataset",
    "field",
    "claims",
    "sources",
    "applicability",
    "observations",
    "issues"
  ],
  "additionalProperties": false,
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "omnisus: metadados resolvidos de uma coluna",
  "$defs": {
    "source": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "category": {
          "type": "string",
          "minLength": 1
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "publisher": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "authority": {
          "enum": [
            "official",
            "secondary"
          ]
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "bytes": {
          "type": "integer",
          "minimum": 1
        },
        "edition": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "published_on": {
          "type": [
            "string",
            "null"
          ],
          "format": "date"
        },
        "retrieved_on": {
          "type": "string",
          "format": "date"
        },
        "last_checked_on": {
          "type": "string",
          "format": "date"
        }
      },
      "required": [
        "id",
        "category",
        "title",
        "publisher",
        "authority",
        "url",
        "sha256",
        "bytes",
        "edition",
        "published_on",
        "retrieved_on",
        "last_checked_on"
      ],
      "additionalProperties": false
    },
    "evidence": {
      "type": "object",
      "properties": {
        "source_id": {
          "type": "string",
          "minLength": 1
        },
        "pages": {
          "type": "array",
          "items": {
            "type": "integer",
            "minimum": 1
          },
          "uniqueItems": true
        },
        "locator": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "source_id",
        "pages",
        "locator"
      ],
      "additionalProperties": false
    },
    "claim": {
      "type": "object",
      "properties": {
        "target": {
          "type": "string",
          "pattern": "^/field/"
        },
        "value_sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "status": {
          "enum": [
            "unreviewed",
            "verified_in_source",
            "conflicting",
            "not_found"
          ]
        },
        "checked_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date"
        },
        "method": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "reviewer": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "evidence": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/evidence"
          }
        },
        "note": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        }
      },
      "required": [
        "target",
        "value_sha256",
        "status",
        "checked_at",
        "method",
        "reviewer",
        "evidence",
        "note"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "const": "verified_in_source"
              }
            }
          },
          "then": {
            "properties": {
              "checked_at": {
                "type": "string",
                "format": "date"
              },
              "method": {
                "type": "string",
                "minLength": 1
              },
              "reviewer": {
                "type": "string",
                "minLength": 1
              },
              "evidence": {
                "minItems": 1
              }
            }
          }
        }
      ]
    },
    "field": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "physical_name": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "label": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "description": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "physical_type": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string",
                  "minLength": 1
                },
                "length": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 1
                }
              },
              "required": [
                "type",
                "length"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        },
        "logical_type": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "unit": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "format": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "codes": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "value": {
                "type": "string"
              },
              "label": {
                "type": "string",
                "minLength": 1
              },
              "missing_kind": {
                "enum": [
                  "not_missing",
                  "ignored",
                  "not_applicable",
                  "unknown"
                ]
              }
            },
            "required": [
              "value",
              "label",
              "missing_kind"
            ],
            "additionalProperties": false
          }
        },
        "domain": {
          "type": "object",
          "properties": {
            "kind": {
              "enum": [
                "enum",
                "reference",
                "free_text",
                "number",
                "date",
                "unknown"
              ]
            },
            "completeness": {
              "enum": [
                "unknown",
                "partial",
                "complete_in_source",
                "not_applicable"
              ]
            },
            "reference": {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "resource": {
                      "type": "string",
                      "minLength": 1
                    },
                    "version": {
                      "type": "string",
                      "minLength": 1
                    },
                    "key": {
                      "type": "string",
                      "minLength": 1
                    }
                  },
                  "required": [
                    "resource",
                    "version",
                    "key"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "kind",
            "completeness",
            "reference"
          ],
          "additionalProperties": false
        },
        "constraints": {
          "type": [
            "object",
            "null"
          ]
        },
        "relationships": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "derivation": {
          "type": [
            "object",
            "null"
          ]
        }
      },
      "required": [
        "id",
        "name",
        "physical_name",
        "label",
        "description",
        "physical_type",
        "logical_type",
        "unit",
        "format",
        "codes",
        "domain",
        "constraints",
        "relationships",
        "derivation"
      ],
      "additionalProperties": false
    },
    "applicability": {
      "type": "object",
      "properties": {
        "status": {
          "enum": [
            "unknown",
            "confirmed",
            "conflicting",
            "not_applicable"
          ]
        },
        "data_period": {
          "type": [
            "string",
            "null"
          ],
          "minLength": 1
        },
        "valid_from": {
          "type": [
            "string",
            "null"
          ],
          "format": "date"
        },
        "valid_until": {
          "type": [
            "string",
            "null"
          ],
          "format": "date"
        },
        "conditions": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "reason": {
          "type": "string",
          "minLength": 1
        },
        "evidence": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/evidence"
          }
        }
      },
      "required": [
        "status",
        "data_period",
        "valid_from",
        "valid_until",
        "conditions",
        "reason",
        "evidence"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "status": {
                "const": "confirmed"
              }
            }
          },
          "then": {
            "properties": {
              "evidence": {
                "minItems": 1
              }
            }
          }
        }
      ]
    }
  }
}
