{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:open-utility-stack:flex-offer:1",
  "title": "flex-offer@1",
  "description": "An aggregator offers flexibility, answering a flex-request@1 or unsolicited: one or more priced options, of which the grid operator may order at most one. A profile of UFTP 3.1 FlexOffer (§ 4.2.26).",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "profile",
    "market",
    "expiration",
    "unsolicited",
    "options"
  ],
  "properties": {
    "profile": {
      "const": "flex-offer@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"
      }
    },
    "expiration": {
      "$ref": "urn:open-utility-stack:common:time:1#/$defs/Instant"
    },
    "unsolicited": {
      "type": "boolean"
    },
    "flex_request": {
      "description": "The message id of the request this answers.",
      "$ref": "urn:open-utility-stack:common:flex:1#/$defs/MessageId"
    },
    "baseline": {
      "$ref": "urn:open-utility-stack:common:flex:1#/$defs/Baseline"
    },
    "options": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "option_reference",
          "price",
          "min_activation_factor",
          "isps"
        ],
        "properties": {
          "option_reference": {
            "type": "string",
            "pattern": "\\S",
            "maxLength": 64
          },
          "price": {
            "$ref": "urn:open-utility-stack:common:money:1#/$defs/Money"
          },
          "min_activation_factor": {
            "$ref": "urn:open-utility-stack:common:flex:1#/$defs/Factor"
          },
          "isps": {
            "description": "The offered flex power per ISP: negative for less consumption.",
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "urn:open-utility-stack:common:flex:1#/$defs/PowerIsp"
            }
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "unsolicited": {
            "const": false
          }
        }
      },
      "then": {
        "required": [
          "flex_request"
        ]
      }
    }
  ]
}
