{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:open-utility-stack:common:flex:1",
  "title": "common/flex@1",
  "description": "What the four flexibility profiles share: the market context of a UFTP exchange, ISP spans and powers. Signs follow UFTP 3.1 § 4.2.1: positive is consumption; a flex power is negative for less consumption or more production.",
  "$defs": {
    "Watts": {
      "description": "Power in whole watts; positive is consumption (UFTP 3.1 § 4.2.1). Within ±2^53 so the digest form is exact.",
      "type": "integer",
      "minimum": -9007199254740992,
      "maximum": 9007199254740992
    },
    "EntityAddress": {
      "description": "A UFTP entity address: `ean.<18 digits>` or `ea1.<yyyy-mm>.<domain>:<id>`.",
      "type": "string",
      "pattern": "^(ean\\.[0-9]{18}|ea1\\.[0-9]{4}-[0-9]{2}\\.[a-z0-9.-]+:\\S+)$",
      "maxLength": 128
    },
    "MessageId": {
      "description": "A UFTP message id (a UUID), the reference the next message in the chain quotes.",
      "type": "string",
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    },
    "Market": {
      "description": "The UFTP header context: which congestion point, which day, which ISP length, between whom.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "congestion_point",
        "period",
        "isp_duration",
        "sender",
        "recipient",
        "message_id"
      ],
      "properties": {
        "congestion_point": {
          "$ref": "#/$defs/EntityAddress"
        },
        "period": {
          "description": "The day, in the zone its ISPs are counted in.",
          "$ref": "urn:open-utility-stack:common:time:1#/$defs/ZonedDate"
        },
        "isp_duration": {
          "description": "ISO 8601 duration; every European market uses PT15M.",
          "type": "string",
          "pattern": "^PT([1-9][0-9]*)M$"
        },
        "sender": {
          "description": "The sender's UFTP domain.",
          "type": "string",
          "pattern": "^[a-z0-9.-]+\\.[a-z]{2,}$",
          "maxLength": 253
        },
        "recipient": {
          "description": "The recipient's UFTP domain.",
          "type": "string",
          "pattern": "^[a-z0-9.-]+\\.[a-z]{2,}$",
          "maxLength": 253
        },
        "message_id": {
          "$ref": "#/$defs/MessageId"
        },
        "conversation_id": {
          "description": "UFTP's ConversationID. Absent means the message's own `message_id`: an unsolicited message is a conversation of its own. Present only when it differs, for an answer it is the request's.",
          "$ref": "#/$defs/MessageId"
        }
      }
    },
    "Span": {
      "description": "ISPs `start` to `start + duration − 1`, numbered from 1 per day (a DST day has 92 or 100 at PT15M; up to 1500 at PT1M on the 25-hour day).",
      "type": "object",
      "required": [
        "start",
        "duration"
      ],
      "properties": {
        "start": {
          "$ref": "#/$defs/IspNumber"
        },
        "duration": {
          "$ref": "#/$defs/IspNumber"
        }
      }
    },
    "PowerIsp": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "start",
        "duration",
        "power"
      ],
      "properties": {
        "start": {
          "$ref": "#/$defs/IspNumber"
        },
        "duration": {
          "$ref": "#/$defs/IspNumber"
        },
        "power": {
          "description": "Power in whole watts; positive is consumption (UFTP 3.1 § 4.2.1). Within ±2^53 so the digest form is exact.",
          "type": "integer",
          "minimum": -9007199254740992,
          "maximum": 9007199254740992
        }
      }
    },
    "Baseline": {
      "description": "How the deviation is measured: a D-Prognosis message, or a method id. One of the two.",
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "maxProperties": 1,
      "properties": {
        "d_prognosis": {
          "$ref": "#/$defs/MessageId"
        },
        "method": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]*@[1-9][0-9]*$",
          "maxLength": 40,
          "description": "A baseline method id: `dprognosis@1` (the aggregator's D-Prognosis as sent, UFTP's default), `schedule@1` (a schedule declared before the event), `mbma@1` (meter before / meter after: the mean of the last n ISPs before the event, held flat), `xofy@1` (the mean of the X highest of Y comparable days). Another id only by bilateral contract; a consumer refuses an id it does not know."
        }
      }
    },
    "Factor": {
      "description": "A share from 0 to 1, as a decimal string.",
      "type": "string",
      "pattern": "^(0(\\.[0-9]+)?|1(\\.0+)?)$"
    },
    "IspNumber": {
      "description": "An ISP number within a day, from 1: up to 100 at PT15M on the 25-hour day, up to 1500 at PT1M.",
      "type": "integer",
      "minimum": 1,
      "maximum": 1500
    }
  }
}
