{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://hotosm.github.io/fAIr-models/schemas/v1.0.0/local-model/schema.json",
  "title": "fAIr Local Model Extension",
  "description": "STAC extension for fAIr finetuned (local) model items. Extends MLM with training provenance and evaluation metadata.",
  "oneOf": [
    {
      "allOf": [
        {
          "$ref": "#/definitions/stac_extensions"
        },
        {
          "type": "object",
          "required": [
            "type",
            "properties",
            "assets"
          ],
          "properties": {
            "type": {
              "const": "Feature"
            },
            "properties": {
              "allOf": [
                {
                  "required": [
                    "title",
                    "description",
                    "mlm:name",
                    "mlm:architecture",
                    "mlm:tasks",
                    "mlm:framework",
                    "mlm:framework_version",
                    "mlm:pretrained",
                    "mlm:pretrained_source",
                    "mlm:input",
                    "mlm:output",
                    "mlm:hyperparameters",
                    "keywords",
                    "version",
                    "deprecated",
                    "fair:user_id"
                  ]
                },
                {
                  "$ref": "#/definitions/fields"
                }
              ]
            },
            "assets": {
              "type": "object",
              "required": [
                "model",
                "source-code"
              ],
              "properties": {
                "model": {
                  "type": "object",
                  "required": [
                    "href"
                  ],
                  "properties": {
                    "href": {
                      "type": "string",
                      "minLength": 1
                    },
                    "mlm:artifact_type": {
                      "type": "string"
                    },
                    "zenml:artifact_version_id": {
                      "type": "string"
                    }
                  }
                },
                "source-code": {
                  "type": "object",
                  "required": [
                    "href"
                  ],
                  "properties": {
                    "href": {
                      "type": "string",
                      "minLength": 1
                    },
                    "mlm:entrypoint": {
                      "type": "string",
                      "minLength": 1
                    }
                  }
                }
              }
            }
          }
        }
      ]
    }
  ],
  "definitions": {
    "stac_extensions": {
      "type": "object",
      "required": [
        "stac_extensions"
      ],
      "properties": {
        "stac_extensions": {
          "type": "array",
          "contains": {
            "const": "https://hotosm.github.io/fAIr-models/schemas/v1.0.0/local-model/schema.json"
          }
        }
      }
    },
    "fields": {
      "type": "object",
      "properties": {
        "fair:user_id": {
          "type": "string",
          "minLength": 1
        },
        "fair:base_model_id": {
          "type": "string"
        },
        "fair:dataset_id": {
          "type": "string"
        },
        "fair:labeled_chip_count": {
          "type": "integer",
          "minimum": 1
        },
        "fair:training_started_at": {
          "type": "string",
          "format": "date-time"
        },
        "fair:training_ended_at": {
          "type": "string",
          "format": "date-time"
        },
        "fair:training_duration_seconds": {
          "type": "number",
          "minimum": 0
        },
        "fair:split": {
          "type": "object",
          "properties": {
            "strategy": {
              "type": "string"
            },
            "ratio": {
              "type": "number"
            },
            "seed": {
              "type": "integer"
            }
          }
        },
        "fair:metrics_spec": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "name"
            ],
            "properties": {
              "name": {
                "type": "string"
              }
            }
          }
        },
        "mlm:name": {
          "type": "string",
          "minLength": 1
        },
        "mlm:architecture": {
          "type": "string"
        },
        "mlm:tasks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "mlm:framework": {
          "type": "string"
        },
        "mlm:framework_version": {
          "type": "string"
        },
        "mlm:pretrained": {
          "type": "boolean"
        },
        "mlm:pretrained_source": {
          "type": "string"
        },
        "mlm:input": {
          "type": "array",
          "minItems": 1
        },
        "mlm:output": {
          "type": "array",
          "minItems": 1
        },
        "mlm:hyperparameters": {
          "type": "object"
        },
        "keywords": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "deprecated": {
          "type": "boolean"
        }
      },
      "patternProperties": {
        "^(?!fair:)": {}
      }
    }
  }
}