{
  "type": "object",
  "properties": {
    "schema_version": {
      "const": 1
    },
    "tool_id": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[a-z][a-z0-9_]*$"
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "description": {
      "type": "string",
      "minLength": 1
    },
    "category": {
      "enum": [
        "core",
        "data_acquisition",
        "model"
      ]
    },
    "skill_id": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[a-z][a-z0-9_-]*$"
    },
    "owner_role": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[a-z][a-z0-9-]*$"
    },
    "implementation_status": {
      "enum": [
        "implemented",
        "template",
        "reference"
      ]
    },
    "registration_status": {
      "enum": [
        "registered",
        "catalogued"
      ]
    },
    "entrypoint": {
      "type": "object",
      "properties": {
        "kind": {
          "enum": [
            "cli",
            "python_script",
            "r_script",
            "template",
            "reference"
          ]
        },
        "path": {
          "type": "string",
          "minLength": 1
        },
        "module": {
          "const": "runtime.cli"
        },
        "subcommand": {
          "enum": [
            "list-datasets",
            "describe-dataset",
            "search-datasets",
            "check-availability",
            "draft-causal-plan",
            "list-tools",
            "describe-tool",
            "check-tool",
            "run-tool"
          ]
        },
        "argument_bindings": {
          "type": "object",
          "additionalProperties": {
            "type": "string",
            "pattern": "^(--[a-z][a-z0-9-]*(=)?|positional:[0-9]+|env:UNIT_PRICE_OUT_DIR)$"
          }
        },
        "default_arguments": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        }
      },
      "required": [
        "kind",
        "path",
        "argument_bindings"
      ],
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "kind": {
                "const": "cli"
              }
            }
          },
          "then": {
            "required": [
              "module",
              "subcommand"
            ],
            "properties": {
              "path": {
                "const": "runtime/cli.py"
              }
            }
          },
          "else": {
            "not": {
              "anyOf": [
                {
                  "required": [
                    "module"
                  ]
                },
                {
                  "required": [
                    "subcommand"
                  ]
                }
              ]
            }
          }
        }
      ]
    },
    "input_schema": {
      "type": "object",
      "properties": {
        "type": {
          "const": "object"
        },
        "properties": {
          "type": "object"
        },
        "required": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "additionalProperties": {
          "const": false
        }
      },
      "required": [
        "type",
        "properties",
        "additionalProperties"
      ],
      "additionalProperties": false
    },
    "output_schema": {
      "type": "object"
    },
    "requirements": {
      "type": "object",
      "properties": {
        "python": {
          "type": "string",
          "pattern": "^>=3\\.[0-9]{1,2}(?:\\.[0-9]{1,2})?$"
        },
        "python_packages": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "pattern": "^[A-Za-z0-9][A-Za-z0-9_.-]*$"
          },
          "uniqueItems": true
        },
        "executables": {
          "type": "array",
          "items": {
            "enum": [
              "java",
              "Rscript",
              "node"
            ]
          },
          "uniqueItems": true
        },
        "r_packages": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "pattern": "^[A-Za-z][A-Za-z0-9.]*$"
          },
          "uniqueItems": true
        },
        "configuration": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "AIRMOSAIC_ASSETS_DIR"
                  },
                  "role": {
                    "const": "workspace"
                  },
                  "kind": {
                    "const": "directory"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "AIRMOSAIC_CONFIG_DIR"
                  },
                  "role": {
                    "const": "config"
                  },
                  "kind": {
                    "const": "directory"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "AIRMOSAIC_AUTH_DIR"
                  },
                  "role": {
                    "const": "auth"
                  },
                  "kind": {
                    "const": "directory"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "GCAM_RELEASE_DIR"
                  },
                  "role": {
                    "const": "model"
                  },
                  "kind": {
                    "const": "directory"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "UNIT_PRICE_OUT_DIR"
                  },
                  "role": {
                    "const": "output"
                  },
                  "kind": {
                    "const": "directory"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "PM25_HIA_OUTPUT_DIR"
                  },
                  "role": {
                    "const": "output"
                  },
                  "kind": {
                    "const": "directory"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "PM25_HIA_CONC_DIR"
                  },
                  "role": {
                    "const": "input"
                  },
                  "kind": {
                    "const": "directory"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "PM25_HIA_POP_DIR"
                  },
                  "role": {
                    "const": "input"
                  },
                  "kind": {
                    "const": "directory"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "PM25_HIA_MORT_FILE"
                  },
                  "role": {
                    "const": "input"
                  },
                  "kind": {
                    "const": "file"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "PM25_HIA_RR_FILE"
                  },
                  "role": {
                    "const": "input"
                  },
                  "kind": {
                    "const": "file"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "PM25_HIA_POP_FILE"
                  },
                  "role": {
                    "const": "input"
                  },
                  "kind": {
                    "const": "file"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "const": "PM25_HIA_SHP_DIR"
                  },
                  "role": {
                    "const": "input"
                  },
                  "kind": {
                    "const": "directory"
                  }
                },
                "required": [
                  "name",
                  "role",
                  "kind"
                ],
                "additionalProperties": false
              }
            ]
          },
          "uniqueItems": true
        },
        "resources": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "root": {
                "const": "GCAM_RELEASE_DIR"
              },
              "path": {
                "type": "string",
                "minLength": 1
              },
              "kind": {
                "enum": [
                  "file",
                  "directory"
                ]
              }
            },
            "required": [
              "root",
              "path",
              "kind"
            ],
            "additionalProperties": false
          },
          "uniqueItems": true
        },
        "manual_checks": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        }
      },
      "required": [
        "python",
        "python_packages",
        "executables",
        "r_packages",
        "configuration",
        "resources",
        "manual_checks"
      ],
      "additionalProperties": false
    },
    "authentication": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "method": {
              "const": "none"
            }
          },
          "required": [
            "method"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "method": {
              "const": "browser_session"
            },
            "profile_id": {
              "enum": [
                "csmar",
                "ihme-gbd"
              ]
            }
          },
          "required": [
            "method",
            "profile_id"
          ],
          "additionalProperties": false
        }
      ]
    },
    "effects": {
      "type": "object",
      "properties": {
        "reads": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "writes": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "network": {
          "type": "boolean"
        }
      },
      "required": [
        "reads",
        "writes",
        "network"
      ],
      "additionalProperties": false
    },
    "documentation": {
      "type": "string",
      "minLength": 1
    },
    "execution": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "enabled": {
              "const": false
            }
          },
          "required": [
            "enabled"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "enabled": {
              "const": true
            },
            "adapter": {
              "enum": [
                "core_cli",
                "worldpop",
                "csmar",
                "gbd",
                "gcam_extract",
                "gcam_aggregate",
                "gcam_inspect",
                "gcam_plot",
                "mlr3_regression",
                "ml_python_regression"
              ]
            },
            "path_parameters": {
              "type": "object",
              "additionalProperties": {
                "enum": [
                  "input_file",
                  "configuration_file",
                  "output_directory",
                  "output_file"
                ]
              }
            }
          },
          "required": [
            "enabled",
            "adapter",
            "path_parameters"
          ],
          "additionalProperties": false
        }
      ]
    }
  },
  "required": [
    "schema_version",
    "tool_id",
    "title",
    "description",
    "category",
    "skill_id",
    "owner_role",
    "implementation_status",
    "registration_status",
    "entrypoint",
    "input_schema",
    "output_schema",
    "requirements",
    "authentication",
    "effects",
    "documentation",
    "execution"
  ],
  "additionalProperties": false,
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "AirMosaic tool manifest v1",
  "allOf": [
    {
      "if": {
        "properties": {
          "implementation_status": {
            "const": "implemented"
          }
        }
      },
      "then": {
        "properties": {
          "registration_status": {
            "const": "registered"
          },
          "entrypoint": {
            "properties": {
              "kind": {
                "enum": [
                  "cli",
                  "python_script",
                  "r_script"
                ]
              }
            }
          }
        }
      },
      "else": {
        "properties": {
          "registration_status": {
            "const": "catalogued"
          },
          "entrypoint": {
            "properties": {
              "kind": {
                "enum": [
                  "template",
                  "reference"
                ]
              }
            }
          }
        }
      }
    }
  ]
}
