{
  "consumes": ["application/json"],
  "definitions": {
    "branch": {
      "description": "information on a single branch",
      "properties": {
        "branch_startdate": {
          "description": "Branch start date",
          "type": "string"
        },
        "distance_to_property": {
          "description": "distance from current property to closest branch (in meters) (or none, if latitude and longitude weren't provided)"
        },
        "id": { "description": "Branch identifier", "type": "number" },
        "latitude": {
          "description": "Branch location (lat)",
          "type": "number"
        },
        "longitude": {
          "description": "Branch location (long)",
          "type": "number"
        },
        "name": { "description": "Company name", "type": "string" }
      },
      "required": [
        "id",
        "branch_startdate",
        "name",
        "distance_to_property",
        "longitude",
        "latitude"
      ],
      "type": "object"
    },
    "company-info": {
      "properties": {
        "company_delta_employees": {
          "description": "Relative change in number of fulltime employees between this year and last year"
        },
        "company_delta_revenue": {
          "description": "Relative change in company revenue between this year and last year"
        },
        "company_enterprisenumber": { "description": "Unique company ID" },
        "company_equity": { "description": "Current company equity" },
        "company_gain_loss": {
          "description": "Current company profit or loss"
        },
        "company_headquarters": {
          "description": "City where the company headquarters are located"
        },
        "company_n_branches": { "description": "Current number of branches" },
        "company_n_employees": {
          "description": "Current number of fulltime employees"
        },
        "company_name": { "description": "Company Name" },
        "company_revenue": { "description": "Current company revenue" },
        "company_startdate": { "description": "Company start date" },
        "company_url": {
          "description": "link to the company website (not often provided)"
        },
        "distance_to_property": {
          "description": "Distance (in m) from the current property to the nearest branch of this company"
        },
        "nace_code": {
          "description": "4-digit label of the company's main activities",
          "type": "string"
        }
      },
      "required": [
        "company_delta_employees",
        "company_delta_revenue",
        "company_enterprisenumber",
        "company_equity",
        "company_gain_loss",
        "company_headquarters",
        "company_n_branches",
        "company_n_employees",
        "company_name",
        "company_revenue",
        "company_startdate",
        "company_url",
        "nace_code"
      ],
      "type": "object"
    },
    "company-response": {
      "description": "All branches from this company",
      "properties": {
        "data": {
          "properties": {
            "branches": {
              "items": { "$ref": "#/definitions/branch" },
              "type": "array"
            },
            "company_enterprisenumber": {
              "description": "the enterprise number (without \"BE\")",
              "type": "string"
            }
          },
          "required": ["company_enterprisenumber", "branches"],
          "type": "object"
        }
      },
      "required": ["data"],
      "type": "object"
    },
    "model-input": {
      "properties": {
        "input": {
          "description": "property info",
          "properties": {
            "area": { "example": 8000, "type": "number" },
            "area_building": { "example": 5000, "type": "number" },
            "house_number": { "example": "2", "type": "string" },
            "latitude": { "example": "51.03", "type": "string" },
            "longitude": { "example": "3.81", "type": "string" },
            "municipality": { "example": "Gent", "type": "string" },
            "n_companies": { "example": 4, "type": "number" },
            "n_parcels": { "example": 1, "type": "number" },
            "post_code": { "example": "9000", "type": "string" },
            "street": { "example": "Korenmarkt", "type": "string" }
          },
          "required": ["area_building", "area", "n_parcels", "n_companies"],
          "type": "object"
        }
      },
      "required": ["input"],
      "type": "object"
    },
    "model-output": {
      "properties": {
        "data": {
          "items": { "$ref": "#/definitions/nace-prediction" },
          "type": "array"
        }
      },
      "required": ["data"],
      "type": "object"
    },
    "nace-prediction": {
      "properties": {
        "explanation": {
          "description": "relative importances of features in the making of this prediction",
          "type": "object"
        },
        "label": {
          "description": "human readable version of the nace code",
          "type": "string"
        },
        "nace": {
          "description": "4-digit label of the company's main activities",
          "type": "string"
        },
        "score": {
          "description": "relative score assigned to this nace code by the ML model",
          "type": "number"
        },
        "stats": {
          "description": "actual values used to predict the nace code",
          "type": "object"
        }
      },
      "required": ["label", "nace", "score"],
      "type": "object"
    },
    "nace-response": {
      "properties": {
        "data": {
          "items": { "$ref": "#/definitions/company-info" },
          "type": "array"
        }
      },
      "required": ["data"],
      "type": "object"
    },
    "status-response": {
      "properties": {
        "payload": { "description": "Status OK", "type": "boolean" }
      },
      "required": ["payload"],
      "type": "object"
    }
  },
  "info": {
    "description": "MME API for activity predictions and company information",
    "title": "MARCH Matching Engine API",
    "version": "3.0.0"
  },
  "paths": {
    "/check-loaded-data": {
      "get": {
        "operationId": "app.flask.routes.DataCheck.get",
        "parameters": [
          {
            "description": "Needed to get authorized",
            "in": "query",
            "name": "access_token",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "schema": { "$ref": "#/definitions/status-response" }
          }
        },
        "summary": "Checks if the data is loaded. If not, it loads anyway.",
        "tags": ["meta"]
      }
    },
    "/company/{company_id}": {
      "get": {
        "operationId": "app.flask.routes.Company.get",
        "parameters": [
          {
            "description": "Needed to get authorized",
            "in": "query",
            "name": "access_token",
            "required": true,
            "type": "string"
          },
          {
            "description": "Company enterprise number (excluding 'BE')",
            "in": "path",
            "name": "company_id",
            "required": true,
            "type": "string"
          },
          {
            "description": "latitude of the current property",
            "in": "query",
            "name": "latitude",
            "required": false,
            "type": "string"
          },
          {
            "description": "longitude of the current property",
            "in": "query",
            "name": "longitude",
            "required": false,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "schema": { "$ref": "#/definitions/company-response" }
          }
        },
        "summary": "Get information on a single company.",
        "tags": ["core"]
      }
    },
    "/health": {
      "get": {
        "operationId": "app.flask.routes.Health.get",
        "responses": { "200": { "description": "OK" } },
        "summary": "Endpoint for Health Probe",
        "tags": ["meta"]
      }
    },
    "/load-data": {
      "get": {
        "operationId": "app.flask.routes.DataLoad.get",
        "parameters": [
          {
            "description": "Needed to get authorized",
            "in": "query",
            "name": "access_token",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "schema": { "$ref": "#/definitions/status-response" }
          }
        },
        "summary": "Loads the databases (if they haven't been loaded yet). Also prepares the model for inference.",
        "tags": ["meta"]
      }
    },
    "/model": {
      "post": {
        "operationId": "app.flask.routes.Model.post",
        "parameters": [
          {
            "description": "Needed to get authorized",
            "in": "query",
            "name": "access_token",
            "required": true,
            "type": "string"
          },
          {
            "description": "Include an explanation of the model\\'s prediction. (This call is faster without explanation)",
            "enum": ["explanation"],
            "in": "query",
            "name": "include",
            "required": false,
            "type": "string"
          },
          {
            "description": "Property info",
            "in": "body",
            "name": "payload",
            "required": true,
            "schema": { "$ref": "#/definitions/model-input" }
          }
        ],
        "produces": ["application/json"],
        "responses": {
          "200": {
            "description": "success",
            "schema": { "$ref": "#/definitions/model-output" }
          }
        },
        "summary": "Predicts which activities are likely to be performed at this location.",
        "tags": ["core"]
      }
    },
    "/nace/{nace_code}": {
      "get": {
        "operationId": "app.flask.routes.Nace.get",
        "parameters": [
          {
            "description": "Needed to get authorized",
            "in": "query",
            "name": "access_token",
            "required": true,
            "type": "string"
          },
          {
            "description": "NACE label (level 4) describing company activities",
            "in": "path",
            "name": "nace_code",
            "required": true,
            "type": "string"
          },
          {
            "description": "latitude of the current property",
            "in": "query",
            "name": "latitude",
            "required": false,
            "type": "string"
          },
          {
            "description": "longitude of the current property",
            "in": "query",
            "name": "longitude",
            "required": false,
            "type": "string"
          },
          {
            "description": "filter companies with their closest branch located inside a radius around the current property (in km)",
            "in": "query",
            "name": "max_radius",
            "required": false,
            "type": "number"
          },
          {
            "description": "filter companies with their closest branch located outside a radius around the current property (in km)",
            "in": "query",
            "name": "min_radius",
            "required": false,
            "type": "number"
          },
          {
            "description": "Sort the companies based on this property. default=ascending. Prepend a dash (\"-\") to sort descending.",
            "enum": [
              "company_n_employees",
              "company_n_branches",
              "company_revenue",
              "company_gain_loss",
              "company_equity",
              "company_age",
              "company_delta_employees",
              "company_delta_revenue",
              "distance_to_property",
              "-company_n_employees",
              "-company_n_branches",
              "-company_revenue",
              "-company_gain_loss",
              "-company_equity",
              "-company_age",
              "-company_delta_employees",
              "-company_delta_revenue",
              "-distance_to_property"
            ],
            "in": "query",
            "name": "sort",
            "required": false,
            "type": "string"
          },
          {
            "default": 10,
            "description": "Number of records per page.",
            "in": "query",
            "name": "page[size]",
            "required": false,
            "type": "integer"
          },
          {
            "default": 0,
            "description": "Page offset.",
            "in": "query",
            "name": "page[number]",
            "required": false,
            "type": "integer"
          },
          {
            "description": "Minimum company age.",
            "in": "query",
            "name": "min_company_age",
            "required": false,
            "type": "number"
          },
          {
            "description": "Maximum company age.",
            "in": "query",
            "name": "max_company_age",
            "required": false,
            "type": "number"
          },
          {
            "description": "Minimum company number of branches.",
            "in": "query",
            "name": "min_company_n_branches",
            "required": false,
            "type": "integer"
          },
          {
            "description": "Maximum company number of branches.",
            "in": "query",
            "name": "max_company_n_branches",
            "required": false,
            "type": "integer"
          },
          {
            "description": "Minimum company number of employees..",
            "in": "query",
            "name": "min_company_n_employees",
            "required": false,
            "type": "integer"
          },
          {
            "description": "Maximum company number of employees.",
            "in": "query",
            "name": "max_company_n_employees",
            "required": false,
            "type": "integer"
          },
          {
            "description": "Minimum company equity.",
            "in": "query",
            "name": "min_company_equity",
            "required": false,
            "type": "number"
          },
          {
            "description": "Maximum company equity.",
            "in": "query",
            "name": "max_company_equity",
            "required": false,
            "type": "number"
          },
          {
            "description": "Minimum company revenue.",
            "in": "query",
            "name": "min_company_revenue",
            "required": false,
            "type": "number"
          },
          {
            "description": "Maximum company revenue.",
            "in": "query",
            "name": "max_company_revenue",
            "required": false,
            "type": "number"
          },
          {
            "description": "Minimum company gain/loss.",
            "in": "query",
            "name": "min_company_gain_loss",
            "required": false,
            "type": "number"
          },
          {
            "description": "Maximum company gain/loss.",
            "in": "query",
            "name": "max_company_gain_loss",
            "required": false,
            "type": "number"
          }
        ],
        "responses": {
          "200": {
            "description": "success",
            "schema": { "$ref": "#/definitions/nace-response" }
          }
        },
        "summary": "Gets information from companies with this 4-digit NACE code",
        "tags": ["core"]
      }
    }
  },
  "produces": ["application/json"],
  "swagger": "2.0",
  "tags": [
    { "description": "Meta functionality", "name": "meta" },
    { "description": "Core MME functionality", "name": "core" }
  ]
}
