{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "schema_version": {
      "type": "string",
      "const": "1.1.0"
    },
    "asset_id": {
      "type": "string",
      "pattern": "^(?:[a-z0-9]+(?:-[a-z0-9]+)*\\/){3}[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "description": {
      "type": "string"
    },
    "publisher": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "name": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "name"
      ],
      "additionalProperties": false
    },
    "publication": {
      "type": "object",
      "properties": {
        "slug": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "title": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "slug",
        "title"
      ],
      "additionalProperties": false
    },
    "release": {
      "type": "object",
      "properties": {
        "slug": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "issued_date": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "slug",
        "label"
      ],
      "additionalProperties": false
    },
    "source": {
      "type": "object",
      "properties": {
        "url": {
          "type": "string",
          "format": "uri"
        },
        "license": {
          "type": "object",
          "properties": {
            "spdx_or_label": {
              "type": "string",
              "minLength": 1
            },
            "url": {
              "type": "string",
              "format": "uri"
            }
          },
          "required": [
            "spdx_or_label"
          ],
          "additionalProperties": false
        },
        "workbook_sha256": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        }
      },
      "required": [
        "url",
        "license",
        "workbook_sha256"
      ],
      "additionalProperties": false
    },
    "temporal_coverage": {
      "type": "object",
      "properties": {
        "start": {
          "type": "string",
          "minLength": 1
        },
        "end": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "spatial_coverage": {
      "type": "string",
      "minLength": 1
    },
    "structure_tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "distributions": {
      "type": "array",
      "prefixItems": [
        {
          "type": "object",
          "properties": {
            "file": {
              "type": "string",
              "const": "tidy.csv"
            },
            "format": {
              "type": "string",
              "const": "csv"
            },
            "bytes": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "sha256": {
              "type": "string",
              "pattern": "^sha256:[a-f0-9]{64}$"
            }
          },
          "required": [
            "file",
            "format",
            "bytes",
            "sha256"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "file": {
              "type": "string",
              "const": "tidy.json"
            },
            "format": {
              "type": "string",
              "const": "json"
            },
            "bytes": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "sha256": {
              "type": "string",
              "pattern": "^sha256:[a-f0-9]{64}$"
            }
          },
          "required": [
            "file",
            "format",
            "bytes",
            "sha256"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "file": {
              "type": "string",
              "const": "tidy.parquet"
            },
            "format": {
              "type": "string",
              "const": "parquet"
            },
            "bytes": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "sha256": {
              "type": "string",
              "pattern": "^sha256:[a-f0-9]{64}$"
            }
          },
          "required": [
            "file",
            "format",
            "bytes",
            "sha256"
          ],
          "additionalProperties": false
        }
      ],
      "minItems": 3,
      "maxItems": 3,
      "items": false
    },
    "status": {
      "type": "string",
      "enum": [
        "discovered",
        "recipe-draft",
        "generated",
        "approved",
        "deprecated"
      ]
    },
    "provenance": {
      "type": "object",
      "properties": {
        "pipeline_version": {
          "type": "string",
          "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$"
        },
        "run_id": {
          "type": "string",
          "minLength": 1
        },
        "generation_method": {
          "type": "string",
          "enum": [
            "direct_draft",
            "pi",
            "seeded"
          ]
        },
        "generated_at": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$"
        },
        "model": {
          "type": "string",
          "minLength": 1
        },
        "approval": {
          "type": "object",
          "properties": {
            "approved_by": {
              "type": "string",
              "minLength": 1
            },
            "approved_at": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z))$"
            }
          },
          "required": [
            "approved_by",
            "approved_at"
          ],
          "additionalProperties": false
        }
      },
      "required": [
        "pipeline_version",
        "run_id",
        "generation_method",
        "generated_at"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "generation_method": {
                "const": "pi"
              }
            },
            "required": [
              "generation_method"
            ]
          },
          "then": {
            "properties": {
              "model": {}
            },
            "required": [
              "model"
            ]
          },
          "else": {
            "not": {
              "properties": {
                "model": {}
              },
              "required": [
                "model"
              ]
            }
          }
        }
      ]
    }
  },
  "required": [
    "schema_version",
    "asset_id",
    "title",
    "publisher",
    "publication",
    "release",
    "source",
    "distributions",
    "status",
    "provenance"
  ],
  "additionalProperties": false
}
