{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/elhub/main/json-schema/elhub-v1-authorization-document-submission-schema.json",
  "title": "V1AuthorizationDocumentSubmission",
  "x-generated": "2026-10-09",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/elhub-access-api-openapi.yml#/components/schemas/V1AuthorizationDocumentSubmission",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "data"
  ],
  "properties": {
    "data": {
      "$ref": "#/$defs/V1AuthorizationDocumentSubmissionData"
    }
  },
  "$defs": {
    "V1AllowedChanges": {
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "description": "Changes authorized for the listed resources.",
      "required": [
        "validFrom"
      ],
      "properties": {
        "validFrom": {
          "type": "array",
          "minItems": 1,
          "maxItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "format": "date"
          }
        }
      }
    },
    "V1AppliesTo": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "meteringPointId"
      ],
      "properties": {
        "meteringPointId": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "description": "Metering points to which the authorization applies.",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "V1AuthorizationDocumentMeta": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "requestedFrom",
        "requestedTo",
        "language"
      ],
      "properties": {
        "requestedFrom": {
          "type": "string",
          "minLength": 1
        },
        "requestedTo": {
          "type": "string",
          "minLength": 1
        },
        "language": {
          "type": "string",
          "description": "Language used for the generated authorization document.",
          "enum": [
            "nb",
            "nn",
            "en"
          ]
        }
      }
    },
    "V1AuthorizationDocumentScopeProfile": {
      "allOf": [
        {
          "if": {
            "properties": {
              "documentType": {
                "const": "ChangeOfEnergySupplierForOrganization"
              }
            },
            "required": [
              "documentType"
            ]
          },
          "then": {
            "properties": {
              "allowedChanges": {
                "not": {}
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "documentType": {
                "const": "MoveInAndChangeOfEnergySupplierForOrganization"
              }
            },
            "required": [
              "documentType"
            ]
          },
          "then": {
            "required": [
              "allowedChanges"
            ]
          }
        }
      ]
    },
    "V1AuthorizationDocumentSubmissionAttributes": {
      "type": "object",
      "allOf": [
        {
          "$ref": "#/$defs/V1AuthorizationDocumentScopeProfile"
        }
      ],
      "required": [
        "documentType",
        "appliesTo",
        "externalReference"
      ],
      "properties": {
        "documentType": {
          "type": "string",
          "description": "Selects the document-type profile that validates the requested scope and party identifiers.\n",
          "enum": [
            "ChangeOfEnergySupplierForOrganization",
            "MoveInAndChangeOfEnergySupplierForOrganization"
          ]
        },
        "appliesTo": {
          "$ref": "#/$defs/V1AppliesTo"
        },
        "allowedChanges": {
          "$ref": "#/$defs/V1AllowedChanges"
        },
        "externalReference": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255,
          "description": "Reference assigned by the requesting party to the underlying contract or process."
        }
      }
    },
    "V1AuthorizationDocumentSubmissionData": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "attributes",
        "meta"
      ],
      "properties": {
        "type": {
          "type": "string",
          "const": "AuthorizationDocument"
        },
        "attributes": {
          "$ref": "#/$defs/V1AuthorizationDocumentSubmissionAttributes"
        },
        "meta": {
          "$ref": "#/$defs/V1AuthorizationDocumentMeta"
        }
      }
    }
  }
}