{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://codingplans.dev/schemas/schedule.schema.json",
  "title": "Peak pricing schedule",
  "description": "Machine-readable peak/off-peak pricing contract for an API provider.",
  "type": "object",
  "required": [
    "schema_version",
    "provider",
    "name",
    "description",
    "reference_timezone",
    "reference_offset_hours",
    "peak_windows_utc",
    "peak_windows_reference",
    "discount_percent",
    "discount_multiplier",
    "peak_multiplier",
    "applies_to",
    "rates_per_m_tokens",
    "source",
    "source_date",
    "last_updated"
  ],
  "properties": {
    "schema_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "provider": { "type": "string", "minLength": 1 },
    "name": { "type": "string", "minLength": 1 },
    "description": { "type": "string", "minLength": 1 },
    "reference_timezone": { "type": "string", "minLength": 1 },
    "reference_offset_hours": { "type": "number" },
    "peak_windows_utc": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["days", "start", "end"],
        "properties": {
          "days": {
            "type": "array",
            "minItems": 1,
            "items": { "type": "string", "enum": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] }
          },
          "start": { "type": "string", "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$" },
          "end": { "type": "string", "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$" }
        },
        "additionalProperties": true
      }
    },
    "peak_windows_reference": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["days", "start", "end"],
        "properties": {
          "days": { "type": "array", "minItems": 1, "items": { "type": "string" } },
          "start": { "type": "string", "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$" },
          "end": { "type": "string", "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$" }
        },
        "additionalProperties": true
      }
    },
    "off_peak_policy": { "type": "string" },
    "discount_percent": { "type": "number", "minimum": 0, "maximum": 100 },
    "discount_multiplier": { "type": "number", "minimum": 0, "maximum": 1 },
    "peak_multiplier": { "type": "number", "minimum": 1 },
    "applies_to": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } },
    "rates_per_m_tokens": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "object",
        "required": ["off_peak", "peak"],
        "properties": {
          "off_peak": {
            "type": "object",
            "required": ["input", "cache_hit", "output"],
            "properties": {
              "input": { "type": "number", "minimum": 0 },
              "cache_hit": { "type": "number", "minimum": 0 },
              "output": { "type": "number", "minimum": 0 }
            },
            "additionalProperties": true
          },
          "peak": {
            "type": "object",
            "required": ["input", "cache_hit", "output"],
            "properties": {
              "input": { "type": "number", "minimum": 0 },
              "cache_hit": { "type": "number", "minimum": 0 },
              "output": { "type": "number", "minimum": 0 }
            },
            "additionalProperties": true
          }
        },
        "additionalProperties": true
      }
    },
    "status_policy": { "type": "string" },
    "holiday_policy": { "type": "string" },
    "source": { "type": "string", "pattern": "^https://" },
    "source_date": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
    "last_updated": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T" }
  },
  "additionalProperties": true
}
