{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:open-utility-stack:flex-request:1",
  "title": "flex-request@1",
  "description": "A grid operator asks aggregators for flexibility on a congestion point: per ISP, the power range it can accept, and where it needs a deviation. A profile of UFTP 3.1 FlexRequest (§ 4.2.24). Emitted by the DSO role (fms); consumed by aggregators (flexpool).",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "profile",
    "market",
    "revision",
    "expiration",
    "isps"
  ],
  "properties": {
    "profile": {
      "const": "flex-request@1"
    },
    "market": {
      "$ref": "urn:open-utility-stack:common:flex:1#/$defs/Market"
    },
    "contract_id": {
      "type": "string",
      "pattern": "\\S",
      "maxLength": 128
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "pattern": "^[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)*$"
      },
      "additionalProperties": {
        "type": "object"
      }
    },
    "revision": {
      "description": "Incremented with every new revision of the same request.",
      "type": "integer",
      "minimum": 1
    },
    "expiration": {
      "$ref": "urn:open-utility-stack:common:time:1#/$defs/Instant"
    },
    "service_type": {
      "type": "string",
      "pattern": "\\S",
      "maxLength": 64
    },
    "isps": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "start",
          "duration",
          "disposition",
          "min_power",
          "max_power"
        ],
        "properties": {
          "start": {
            "$ref": "urn:open-utility-stack:common:flex:1#/$defs/IspNumber"
          },
          "duration": {
            "$ref": "urn:open-utility-stack:common:flex:1#/$defs/IspNumber"
          },
          "disposition": {
            "description": "`requested`: the DSO needs a deviation in one direction, within the band; `available`: deviations within the band are allowed (UFTP 3.1 § 3.8.2).",
            "enum": [
              "requested",
              "available"
            ]
          },
          "min_power": {
            "description": "Lower bound of the deviation from the baseline the DSO accepts, not absolute power (UFTP § 3.8.2). A requested ISP has one direction: `max_power` ≤ 0 (less consumption) or `min_power` ≥ 0 (more).",
            "$ref": "urn:open-utility-stack:common:flex:1#/$defs/Watts"
          },
          "max_power": {
            "description": "Upper bound of the deviation; see `min_power`.",
            "$ref": "urn:open-utility-stack:common:flex:1#/$defs/Watts"
          }
        },
        "if": {
          "properties": {
            "disposition": {
              "const": "requested"
            }
          }
        },
        "then": {
          "anyOf": [
            {
              "properties": {
                "max_power": {
                  "maximum": 0
                }
              }
            },
            {
              "properties": {
                "min_power": {
                  "minimum": 0
                }
              }
            }
          ]
        }
      }
    }
  }
}
