{
  "id": "iagree-example-api",
  "version": "1.0",
  "type": "template",
  "context": {
	"iAgree": "2.0",
    "provider": "ISA Research Group",
    "infrastructure": {
      "supervisor": "http://supervisor.oai.governify.io/api/v1/",
      "monitor": "http://monitor.governify.io/api/v1/"
    },
    "definitions": {
      "schemas": {
        "animalTypes": {
          "type": "integer",
          "format": "int64",
          "description": "Number of different animal types."
        },
        "resourceInstances": {
          "type": "integer",
          "format": "int64",
          "description": "Number of pet resources"
        },
        "requests": {
          "type": "integer",
          "format": "int64",
          "description": "Number of requests"
        },
        "responseTime": {
          "type": "integer",
          "format": "int64",
          "description": "Time in ms spent by request"
        }
      },
      "scopes": {
        "api": {
          "resource": {
            "description": "Defines the path in which limits will be checked",
            "type": "string"
          },
          "operation": {
            "description": "Defines the operations in which limits will be checked",
            "type": "string"
          }
        },
        "oai": {
          "level": {
            "description": "Defines the level inside the organization in which limits will be checked",
            "type": "string",
            "enum": [
              "account",
              "tenant"
            ]
          },
          "account": {
            "description": "Account ID of current request",
            "type": "string"
          }
        },
        "offering": {
          "plan": {
            "description": "Defines diferent levels of service that are provided",
            "type": "string"
          }
        }
      }
    }
  },
  "terms": {
    "pricing": {
      "scope": {
        "plan": "*"
      },
      "cost": 0,
      "currency": "EUR",
      "billing": {
        "period": "monthly"
      }
    },
    "configurations": {
      "availability": {
        "scope": {
          "plan": {
            "$ref": "#/context/definitions/scopes/offering/plan"
          }
        },
        "of": [
          {
            "scope": {
              "plan": "*"
            },
            "value": "R/00:00:00Z/15:00:00Z"
          },
          {
            "scope": {
              "plan": "pro"
            },
            "value": "R/00:00:00Z/23:59:59Z"
          }
        ]
      },
      "filteringType": {
        "scope": {
          "plan": {
            "$ref": "#/context/definitions/scopes/offering/plan"
          }
        },
        "of": [
          {
            "scope": {
              "plan": "*"
            },
            "value": "none"
          },
          {
            "scope": {
              "plan": "pro"
            },
            "value": "multipleTags"
          }
        ]
      },
      "xmlFormat": {
        "scope": {
          "plan": {
            "$ref": "#/context/definitions/scopes/offering/plan"
          }
        },
        "of": [
          {
            "scope": {
              "plan": "*"
            },
            "value": "false"
          },
          {
            "scope": {
              "plan": "pro"
            },
            "value": "true"
          }
        ]
      }
    },
    "metrics": {
      "requests": {
        "schema": {
          "$ref": "#/context/definitions/schemas/requests"
        },
        "type": "consumption",
        "scope": {
          "resource": {
            "$ref": "#/context/definitions/scopes/api/resource"
          },
          "operation": {
            "$ref": "#/context/definitions/scopes/api/operation"
          },
          "level": {
            "$ref": "#/context/definitions/scopes/oai/level"
          },
          "account": {
            "$ref": "#/context/definitions/scopes/oai/account"
          }
        }
      },
      "resourceInstances": {
        "schema": {
          "$ref": "#/context/definitions/schemas/resourceInstances"
        },
        "type": "check",
        "scope": {
          "resource": {
            "$ref": "#/context/definitions/scopes/api/resource"
          },
          "operation": {
            "$ref": "#/context/definitions/scopes/api/operation"
          },
          "level": {
            "$ref": "#/context/definitions/scopes/oai/level"
          },
          "account": {
            "$ref": "#/context/definitions/scopes/oai/account"
          }
        }
      },
      "animalTypes": {
        "schema": {
          "$ref": "#/context/definitions/schemas/animalTypes"
        },
        "type": "check",
        "scope": {
          "resource": {
            "$ref": "#/context/definitions/scopes/api/resource"
          },
          "operation": {
            "$ref": "#/context/definitions/scopes/api/operation"
          },
          "level": {
            "$ref": "#/context/definitions/scopes/oai/level"
          },
          "account": {
            "$ref": "#/context/definitions/scopes/oai/account"
          }
        }
      },
      "responseTime": {
        "schema": {
          "$ref": "#/context/definitions/schemas/responseTime"
        },
        "type": "consumption",
        "scope": {
          "resource": {
            "$ref": "#/context/definitions/scopes/api/resource"
          },
          "operation": {
            "$ref": "#/context/definitions/scopes/api/operation"
          },
          "level": {
            "$ref": "#/context/definitions/scopes/oai/level"
          },
          "account": {
            "$ref": "#/context/definitions/scopes/oai/account"
          }
        }
      }
    },
    "quotas": [
      {
        "id": "quotas_requests",
        "scope": {
          "plan": {
            "$ref": "#/context/definitions/scopes/offering/plan"
          },
          "resource": {
            "$ref": "#/context/definitions/scopes/api/resource"
          },
          "operation": {
            "$ref": "#/context/definitions/scopes/api/operation"
          },
          "level": {
            "$ref": "#/context/definitions/scopes/oai/level"
          },
          "account": {
            "$ref": "#/context/definitions/scopes/oai/account"
          }
        },
        "over": {
          "requests": {
            "$ref": "#/terms/metrics/requests"
          }
        },
        "of": [
          {
            "scope": {
              "plan": "*",
              "resource": "/pets",
              "operation": "get",
              "level": "account",
              "account": "*"
            },
            "limits": [
              {
                "max": 5,
                "period": "minutely"
              }
            ]
          },
          {
            "scope": {
              "plan": "*",
              "resource": "/pets",
              "operation": "get",
              "level": "tenant",
              "account": {
                "$ref": "#/context/consumer"
              }
            },
            "limits": [
              {
                "max": 40,
                "period": "hourly"
              }
            ]
          },
          {
            "scope": {
              "plan": "*",
              "resource": "/pets",
              "operation": "post",
              "level": "account",
              "account": "*"
            },
            "limits": [
              {
                "max": 3,
                "period": "minutely"
              }
            ]
          },
          {
            "scope": {
              "plan": "pro",
              "resource": "/pets",
              "operation": "get",
              "level": "account",
              "account": "*"
            },
            "limits": [
              {
                "max": 20,
                "period": "minutely"
              }
            ]
          },
          {
            "scope": {
              "plan": "pro",
              "resource": "/pets",
              "operation": "get",
              "level": "tenant",
              "account": {
                "$ref": "#/context/consumer"
              }
            },
            "limits": [
              {
                "max": 100,
                "period": "hourly"
              }
            ]
          },
          {
            "scope": {
              "plan": "pro",
              "resource": "/pets",
              "operation": "post",
              "level": "account",
              "account": "*"
            },
            "limits": [
              {
                "max": 100,
                "period": "minutely"
              }
            ]
          }
        ]
      },
      {
        "id": "quotas_resourceInstances",
        "scope": {
          "plan": {
            "$ref": "#/context/definitions/scopes/offering/plan"
          },
          "resource": {
            "$ref": "#/context/definitions/scopes/api/resource"
          },
          "operation": {
            "$ref": "#/context/definitions/scopes/api/operation"
          },
          "level": {
            "$ref": "#/context/definitions/scopes/oai/level"
          },
          "account": {
            "$ref": "#/context/definitions/scopes/oai/account"
          }
        },
        "over": {
          "resourceInstances": {
            "$ref": "#/terms/metrics/resourceInstances"
          }
        },
        "of": [
          {
            "scope": {
              "plan": "*",
              "resource": "/pets",
              "operation": "post",
              "level": "account",
              "account": "*"
            },
            "limits": [
              {
                "max": 5
              }
            ]
          },
          {
            "scope": {
              "plan": "pro",
              "resource": "/pets",
              "operation": "post",
              "level": "account",
              "account": "*"
            },
            "limits": [
              {
                "max": 500
              }
            ]
          }
        ]
      },
      {
        "id": "quotas_animalTypes",
        "scope": {
          "plan": {
            "$ref": "#/context/definitions/scopes/offering/plan"
          },
          "resource": {
            "$ref": "#/context/definitions/scopes/api/resource"
          },
          "operation": {
            "$ref": "#/context/definitions/scopes/api/operation"
          },
          "level": {
            "$ref": "#/context/definitions/scopes/oai/level"
          },
          "account": {
            "$ref": "#/context/definitions/scopes/oai/account"
          }
        },
        "over": {
          "animalTypes": {
            "$ref": "#/terms/metrics/animalTypes"
          }
        },
        "of": [
          {
            "scope": {
              "plan": "*",
              "resource": "/pets",
              "operation": "post",
              "level": "account",
              "account": "*"
            },
            "limits": [
              {
                "max": 2
              }
            ]
          },
          {
            "scope": {
              "plan": "pro",
              "resource": "/pets",
              "operation": "post",
              "level": "account",
              "account": "*"
            },
            "limits": [
              {
                "max": 5
              }
            ]
          }
        ]
      }
    ],
    "rates": [
      {
        "id": "rates_requests",
        "scope": {
          "plan": {
            "$ref": "#/context/definitions/scopes/offering/plan"
          },
          "resource": {
            "$ref": "#/context/definitions/scopes/api/resource"
          },
          "operation": {
            "$ref": "#/context/definitions/scopes/api/operation"
          },
          "level": {
            "$ref": "#/context/definitions/scopes/oai/level"
          },
          "account": {
            "$ref": "#/context/definitions/scopes/oai/account"
          }
        },
        "over": {
          "requests": {
            "$ref": "#/terms/metrics/requests"
          }
        },
        "of": [
          {
            "scope": {
              "plan": "*",
              "resource": "/pets",
              "operation": "get",
              "level": "account",
              "account": "*"
            },
            "limits": [
              {
                "max": 3,
                "period": "secondly"
              }
            ]
          },
          {
            "scope": {
              "plan": "free",
              "resource": "/pets",
              "operation": "get",
              "level": "account",
              "account": "*"
            },
            "limits": [
              {
                "max": 1,
                "period": "secondly"
              }
            ]
          }
        ]
      }
    ],
    "guarantees": [
      {
        "id": "guarantees_responseTime",
        "scope": {
          "plan": {
            "$ref": "#/context/definitions/scopes/offering/plan"
          },
          "resource": {
            "$ref": "#/context/definitions/scopes/api/resource"
          },
          "operation": {
            "$ref": "#/context/definitions/scopes/api/operation"
          },
          "level": {
            "$ref": "#/context/definitions/scopes/oai/level"
          },
          "account": {
            "$ref": "#/context/definitions/scopes/oai/account"
          }
        },
        "of": [
          {
            "scope": {
              "plan": "*",
              "resource": "*",
              "operation": "*",
              "level": "account",
              "account": "*"
            },
            "objective": "responseTime <= 800",
            "window": {
              "type": "dynamic",
              "period": "daily"
            }
          },
          {
            "scope": {
              "plan": "pro",
              "resource": "*",
              "operation": "*",
              "level": "account",
              "account": "*"
            },
            "objective": "responseTime <= 250",
            "window": {
              "type": "dynamic",
              "period": "daily"
            }
          }
        ]
      }
    ]
  },
  "creationConstraints": {
    "cc_free": {
      "constraint": {
        "over": {
          "$ref": "#/context/definitions/scopes/offering/plan"
        },
        "of": "free"
      }
    },
    "cc_pro": {
      "constraint": {
        "over": {
          "$ref": "#/context/definitions/scopes/offering/plan"
        },
        "of": "pro"
      }
    }
  }
}