{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:ledgermath:prices:1",
  "title": "Price file",
  "description": "A day's copy of what AWS publicly charges for what LedgerMath measures, kept at the path prices/<yyyy>/<mm>/<dd>/aws.json, under the UTC date it was fetched. Added once, never edited. It holds the records the named rule set selected from AWS's Price List offer files, verbatim: each product and each set of On-Demand terms is AWS's own object, parsed and written back with nothing changed but the whitespace between tokens. Each source names the versioned URL its bytes came from, their size and SHA-256, so anyone can download the whole file and cut it again. A price is cited as this file's path, the SKU and the rate code. The root and LedgerMath's own objects are closed; AWS's objects are open, because they are AWS's words.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "provider", "fetched_at", "measured", "rules", "sources"],
  "properties": {
    "schema": { "description": "What this file is, and which version of its shape.", "const": "ledgermath.prices/1" },
    "provider": { "description": "Whose price lists these are.", "const": "aws" },
    "fetched_at": {
      "description": "When the fetch started, UTC, to the millisecond. Its date names the file.",
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$"
    },
    "measured": {
      "description": "What is measured, as LedgerMath's schedule (which benchmarks run on which instance types, in which zone) said when the file was cut: the inputs the rules were given besides the offer files.",
      "type": "object",
      "additionalProperties": false,
      "required": ["region", "instance_types"],
      "properties": {
        "region": { "description": "The Region of the schedule's zone.", "type": "string", "pattern": "^[a-z]{2}-[a-z]+-[0-9]$" },
        "instance_types": {
          "description": "The schedule's instance types, sorted.",
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "type": "string", "pattern": "^[a-z][a-z0-9-]*\\.[a-z0-9]+$" }
        }
      }
    },
    "rules": {
      "description": "The rule set the records were selected with, by name and version. A record a rule of this version does not select is not in the file, whatever AWS charges for it.",
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version"],
      "properties": {
        "name": { "description": "The rule set's name.", "const": "ledgermath.aws-price-rules" },
        "version": { "description": "The rule set's version. A rule set is never changed once a price file names it: a change is a new version.", "type": "integer", "minimum": 1 }
      }
    },
    "sources": {
      "description": "One per offer file the rules read.",
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/source" }
    }
  },
  "$defs": {
    "source": {
      "description": "One offer file the rules read: the versioned URL its bytes were downloaded from, their size and SHA-256, the file's header, what each rule selected from it, and the selected products and their On-Demand terms, verbatim.",
      "type": "object",
      "additionalProperties": false,
      "required": ["offer_code", "url", "version", "publication_date", "bytes", "sha256", "header", "selections", "products", "terms"],
      "properties": {
        "offer_code": { "description": "AWS's offer code, such as AmazonEC2.", "type": "string", "pattern": "^[A-Za-z0-9]+$" },
        "url": {
          "description": "The versioned URL the bytes were downloaded from; never a current URL.",
          "type": "string",
          "pattern": "^https://pricing\\.us-east-1\\.amazonaws\\.com/offers/v1\\.0/aws/[A-Za-z0-9]+/[0-9]{14}/[a-z0-9-]+/index\\.json$"
        },
        "version": { "description": "The offer file's own version.", "type": "string", "pattern": "^[0-9]{14}$" },
        "publication_date": { "description": "The offer file's own publicationDate.", "type": "string", "minLength": 1 },
        "bytes": { "description": "The size of the file downloaded.", "type": "integer", "minimum": 1 },
        "sha256": { "description": "The SHA-256 of the file downloaded.", "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
        "header": {
          "description": "Every top-level member of the offer file other than products and terms, verbatim.",
          "type": "object",
          "required": ["formatVersion", "offerCode", "version", "publicationDate"],
          "properties": {
            "formatVersion": { "description": "The offer file's formatVersion, AWS's, copied as AWS gives it.", "type": "string" },
            "disclaimer": { "description": "The offer file's disclaimer, AWS's words, copied as AWS gives them.", "type": "string" },
            "offerCode": { "description": "The offer file's offerCode, AWS's, copied as AWS gives it: the same as the source's offer_code.", "type": "string" },
            "version": { "description": "The offer file's version, AWS's, copied as AWS gives it: the same as the source's version, and the 14 digits of its url.", "type": "string" },
            "publicationDate": { "description": "The offer file's publicationDate, AWS's, copied as AWS gives it: the same as the source's publication_date.", "type": "string" }
          }
        },
        "selections": {
          "description": "Each rule of the rule set that reads this offer, what it selects, and the SKUs it selected, in the offer file's order.",
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["rule", "selects", "skus"],
            "properties": {
              "rule": { "description": "The rule's name, unique within its rule set.", "type": "string", "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" },
              "selects": { "description": "What the rule selects, in words.", "type": "string", "minLength": 1 },
              "skus": { "description": "The SKUs it selected, in the offer file's order: each is a key of products.", "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1 } }
            }
          }
        },
        "products": {
          "description": "The selected products, verbatim, each under the SKU the offer file files it under.",
          "type": "object",
          "minProperties": 1,
          "additionalProperties": { "$ref": "#/$defs/product" }
        },
        "terms": {
          "description": "The selected products' terms: On-Demand terms only.",
          "type": "object",
          "additionalProperties": false,
          "required": ["OnDemand"],
          "properties": {
            "OnDemand": {
              "description": "Each selected product's On-Demand terms, verbatim: terms.OnDemand.<sku> of the offer file, a map from <sku>.<offerTermCode> to a term.",
              "type": "object",
              "minProperties": 1,
              "additionalProperties": {
                "description": "One selected product's On-Demand terms, under its SKU: terms.OnDemand.<sku> of the offer file, copied as AWS gives it, each term under <sku>.<offerTermCode>.",
                "type": "object",
                "minProperties": 1,
                "additionalProperties": { "$ref": "#/$defs/term" }
              }
            }
          }
        }
      }
    },
    "product": {
      "description": "AWS's product object.",
      "type": "object",
      "required": ["sku", "attributes"],
      "properties": {
        "sku": { "description": "AWS's SKU for the product: the key it is filed under in products.", "type": "string", "minLength": 1 },
        "productFamily": { "description": "The product's family, AWS's, such as Compute Instance or Storage, copied as AWS gives it.", "type": "string" },
        "attributes": {
          "description": "The product's attributes, AWS's, by name, copied as AWS gives them: such as instanceType, regionCode and operatingSystem, which the rules select on.",
          "type": "object",
          "additionalProperties": { "description": "One attribute's value, as AWS gives it.", "type": "string" }
        }
      }
    },
    "term": {
      "description": "AWS's term object.",
      "type": "object",
      "required": ["offerTermCode", "sku", "effectiveDate", "priceDimensions"],
      "properties": {
        "offerTermCode": { "description": "AWS's code for the term: the term is filed under <sku>.<offerTermCode>.", "type": "string", "minLength": 1 },
        "sku": { "description": "The SKU of the product the term is for: the SKU it is filed under.", "type": "string", "minLength": 1 },
        "effectiveDate": { "description": "The term's effectiveDate, AWS's, copied as AWS gives it.", "type": "string" },
        "priceDimensions": {
          "description": "A map from rate code, <sku>.<offerTermCode>.<code>, to a price dimension.",
          "type": "object",
          "minProperties": 1,
          "additionalProperties": { "$ref": "#/$defs/priceDimension" }
        },
        "termAttributes": { "description": "The term's termAttributes, AWS's, copied as AWS gives them.", "type": "object" }
      }
    },
    "priceDimension": {
      "description": "AWS's price dimension: a rate, the unit it is per, and the range of usage it applies to.",
      "type": "object",
      "required": ["rateCode", "unit", "pricePerUnit"],
      "properties": {
        "rateCode": { "description": "AWS's rate code, <sku>.<offerTermCode>.<code>: the price dimension is filed under it, and a price is cited by it.", "type": "string", "minLength": 1 },
        "description": { "description": "AWS's words for the price, copied as AWS gives them, such as $0.096 per On Demand Linux m5.large Instance Hour.", "type": "string" },
        "beginRange": { "description": "Where the range of usage the rate applies to begins, as AWS writes it.", "type": "string" },
        "endRange": { "description": "Where the range of usage the rate applies to ends, as AWS writes it, such as Inf.", "type": "string" },
        "unit": { "description": "The unit the rate is per, AWS's, such as Hrs, copied as AWS gives it.", "type": "string" },
        "pricePerUnit": {
          "description": "The price per unit, by currency, as AWS writes the number.",
          "type": "object",
          "minProperties": 1,
          "additionalProperties": { "description": "The price of one unit in one currency, under the currency's code, such as USD: a decimal number written as a string, as AWS writes it.", "type": "string", "pattern": "^[0-9]+(\\.[0-9]+)?$" }
        },
        "appliesTo": { "description": "AWS's appliesTo list, copied as AWS gives it.", "type": "array", "items": { "type": "string" } }
      }
    }
  }
}
