{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.icop.com.tw/data/data-index.schema.json",
  "title": "ICOP Public Data Index Schema",
  "description": "JSON Schema for validating the ICOP public data discovery index.",
  "type": "object",
  "required": [
    "name",
    "publisher",
    "description",
    "version",
    "status",
    "last_updated",
    "canonical",
    "canonical_datasets",
    "live_apis",
    "api_definition",
    "ai_usage_guidelines",
    "governance"
  ],
  "properties": {
    "$schema": {
      "type": "string",
      "format": "uri"
    },
    "name": {
      "type": "string",
      "minLength": 1
    },
    "publisher": {
      "$ref": "#/$defs/publisher"
    },
    "description": {
      "type": "string",
      "minLength": 1
    },
    "version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "status": {
      "type": "string",
      "enum": [
        "draft",
        "active",
        "deprecated"
      ]
    },
    "last_updated": {
      "type": "string",
      "format": "date"
    },
    "canonical": {
      "$ref": "#/$defs/canonical"
    },
    "canonical_datasets": {
      "type": "object",
      "required": [
        "products",
        "categories"
      ],
      "additionalProperties": {
        "$ref": "#/$defs/dataset"
      }
    },
    "live_apis": {
      "type": "object",
      "required": [
        "index",
        "products",
        "categories",
        "about"
      ],
      "additionalProperties": {
        "$ref": "#/$defs/apiEndpoint"
      }
    },
    "api_definition": {
      "$ref": "#/$defs/apiDefinition"
    },
    "ai_usage_guidelines": {
      "$ref": "#/$defs/aiUsageGuidelines"
    },
    "governance": {
      "$ref": "#/$defs/governance"
    }
  },
  "$defs": {
    "publisher": {
      "type": "object",
      "required": [
        "name",
        "brand",
        "website"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "brand": {
          "type": "string",
          "minLength": 1
        },
        "website": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "canonical": {
      "type": "object",
      "required": [
        "type",
        "url",
        "authority",
        "official",
        "description"
      ],
      "properties": {
        "type": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "authority": {
          "type": "string"
        },
        "official": {
          "type": "boolean"
        },
        "description": {
          "type": "string"
        }
      }
    },
    "dataset": {
      "type": "object",
      "required": [
        "type",
        "format",
        "status",
        "description",
        "url"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "static"
          ]
        },
        "format": {
          "type": "string",
          "enum": [
            "json"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "planned",
            "active",
            "deprecated"
          ]
        },
        "coverage": {
          "type": "string",
          "enum": [
            "partial",
            "complete"
          ]
        },
        "description": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "apiEndpoint": {
      "type": "object",
      "required": [
        "type",
        "version",
        "method",
        "format",
        "status",
        "description",
        "endpoint"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "api"
          ]
        },
        "version": {
          "type": "string"
        },
        "method": {
          "type": "string",
          "enum": [
            "GET"
          ]
        },
        "format": {
          "type": "string",
          "enum": [
            "json"
          ]
        },
        "status": {
          "type": "string",
          "enum": [
            "planned",
            "active",
            "deprecated"
          ]
        },
        "coverage": {
          "type": "string",
          "enum": [
            "partial",
            "complete"
          ]
        },
        "description": {
          "type": "string"
        },
        "endpoint": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "apiDefinition": {
      "type": "object",
      "required": [
        "type",
        "version",
        "status",
        "url"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "OpenAPI"
          ]
        },
        "version": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "active",
            "deprecated"
          ]
        },
        "url": {
          "type": "string",
          "format": "uri"
        }
      }
    },
    "aiUsageGuidelines": {
      "type": "object",
      "required": [
        "recommended_usage",
        "prohibited_assumptions",
        "stability_notice"
      ],
      "properties": {
        "recommended_usage": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "prohibited_assumptions": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "stability_notice": {
          "type": "string"
        }
      }
    },
    "governance": {
      "type": "object",
      "required": [
        "data_owner",
        "versioning_policy",
        "official_reference"
      ],
      "properties": {
        "data_owner": {
          "type": "string"
        },
        "versioning_policy": {
          "type": "string"
        },
        "official_reference": {
          "type": "boolean"
        }
      }
    }
  }
}