{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://hotosm.github.io/fAIr-models/schemas/v1.0.0/base-model/schema.json",
  "title": "fAIr Base Model Extension",
  "description": "STAC extension for fAIr base model items. Extends MLM with fAIr-specific training 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:input",
                    "mlm:output",
                    "mlm:hyperparameters",
                    "keywords",
                    "version",
                    "license",
                    "fair:metrics_spec",
                    "fair:split_spec"
                  ]
                },
                {
                  "$ref": "#/definitions/fields"
                }
              ]
            },
            "assets": {
              "type": "object",
              "required": [
                "model",
                "source-code",
                "mlm:training",
                "mlm:inference"
              ],
              "properties": {
                "model": {
                  "type": "object",
                  "required": [
                    "href"
                  ],
                  "properties": {
                    "href": {
                      "type": "string",
                      "minLength": 1
                    },
                    "mlm:artifact_type": {
                      "type": "string",
                      "enum": [
                        "torch.save",
                        "torch.jit.save",
                        "torch.export.save",
                        "onnx",
                        "pickle",
                        "tf.keras.Model.save",
                        "tf.keras.Model.save_weights",
                        "tf.keras.Model.export"
                      ]
                    }
                  }
                },
                "source-code": {
                  "type": "object",
                  "required": [
                    "href"
                  ],
                  "properties": {
                    "href": {
                      "type": "string",
                      "minLength": 1
                    },
                    "mlm:entrypoint": {
                      "type": "string",
                      "minLength": 1
                    }
                  }
                },
                "mlm:training": {
                  "type": "object",
                  "required": [
                    "href"
                  ],
                  "properties": {
                    "href": {
                      "type": "string",
                      "minLength": 1
                    }
                  }
                },
                "mlm:inference": {
                  "type": "object",
                  "required": [
                    "href"
                  ],
                  "properties": {
                    "href": {
                      "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/base-model/schema.json"
          }
        }
      }
    },
    "fields": {
      "type": "object",
      "properties": {
        "fair:metrics_spec": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "name"
            ],
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        "fair:split_spec": {
          "type": "object",
          "required": [
            "strategy",
            "default_ratio",
            "seed",
            "description"
          ],
          "properties": {
            "strategy": {
              "type": "string",
              "minLength": 1
            },
            "default_ratio": {
              "type": "number",
              "exclusiveMinimum": 0,
              "exclusiveMaximum": 1
            },
            "seed": {
              "type": "integer"
            },
            "description": {
              "type": "string"
            }
          }
        },
        "mlm:name": {
          "type": "string",
          "minLength": 1
        },
        "mlm:architecture": {
          "type": "string",
          "minLength": 1
        },
        "mlm:tasks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "enum": [
              "semantic-segmentation",
              "instance-segmentation",
              "object-detection",
              "classification"
            ]
          }
        },
        "mlm:framework": {
          "type": "string",
          "enum": [
            "PyTorch",
            "TensorFlow"
          ]
        },
        "mlm:framework_version": {
          "type": "string",
          "minLength": 1
        },
        "mlm:pretrained": {
          "type": "boolean"
        },
        "mlm:pretrained_source": {
          "type": [
            "string",
            "null"
          ]
        },
        "mlm:input": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "pre_processing_function"
            ],
            "properties": {
              "pre_processing_function": {
                "type": "object",
                "required": [
                  "format",
                  "expression"
                ],
                "properties": {
                  "format": {
                    "type": "string"
                  },
                  "expression": {}
                }
              }
            }
          }
        },
        "mlm:output": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": [
              "post_processing_function",
              "classification:classes"
            ],
            "properties": {
              "post_processing_function": {
                "type": "object",
                "required": [
                  "format",
                  "expression"
                ],
                "properties": {
                  "format": {
                    "type": "string"
                  },
                  "expression": {}
                }
              },
              "classification:classes": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "name"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "mlm:hyperparameters": {
          "type": "object"
        },
        "keywords": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          }
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "license": {
          "type": "string",
          "enum": [
            "AGPL-3.0-only",
            "MIT",
            "Apache-2.0",
            "BSD-3-Clause"
          ]
        }
      },
      "patternProperties": {
        "^(?!fair:)": {}
      }
    }
  }
}