{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:sitla:payments:1:schema:collection-authorization",
  "$comment": "SPDX-License-Identifier: CC0-1.0; Stripe online adapter, not a new wire/1 record or proof of provider execution.",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "profile": {
      "const": "sitla-collection-authorization/1"
    },
    "authorizationId": {
      "type": "string",
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
    },
    "agent": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "processor": {
      "const": "Stripe"
    },
    "sellerId": {
      "type": "string",
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
    },
    "seller": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "controllerDid": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 2048
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "controllerDid"
      ],
      "additionalProperties": false
    },
    "processorAccount": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "livemode": {
      "enum": [
        0,
        1
      ]
    },
    "currency": {
      "const": "JPY"
    },
    "feeBasisPoints": {
      "type": "integer",
      "minimum": 0,
      "maximum": 10000
    },
    "refundPolicy": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "scope": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "profile"
            },
            "profileVersion": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "termsDigest": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "plans": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "planIndex": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 2
                  },
                  "priceYen": {
                    "type": "integer",
                    "minimum": 50,
                    "maximum": 9007199254740991
                  },
                  "fieldKeys": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 2048
                    },
                    "minItems": 1,
                    "maxItems": 100
                  }
                },
                "required": [
                  "planIndex",
                  "priceYen",
                  "fieldKeys"
                ],
                "additionalProperties": false
              },
              "minItems": 1,
              "maxItems": 100
            }
          },
          "required": [
            "kind",
            "profileVersion",
            "termsDigest",
            "plans"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "const": "work"
            },
            "workId": {
              "type": "string",
              "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
            },
            "buyerId": {
              "type": "string",
              "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
            },
            "termsDigest": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            },
            "amountLimitMinor": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            },
            "funding": {
              "enum": [
                "direct",
                "card-authorization"
              ]
            }
          },
          "required": [
            "kind",
            "workId",
            "buyerId",
            "termsDigest",
            "amountLimitMinor",
            "funding"
          ],
          "additionalProperties": false
        }
      ]
    },
    "authorizedAt": {
      "type": "string",
      "pattern": "^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d(?:\\.\\d{3})?Z$"
    },
    "approvalDigest": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "approval": {
      "type": "object",
      "properties": {
        "operationId": {
          "type": "string",
          "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
        },
        "evidenceDigest": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      },
      "required": [
        "operationId",
        "evidenceDigest"
      ],
      "additionalProperties": false
    },
    "limitations": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 2048
      },
      "minItems": 1,
      "maxItems": 100
    },
    "policy": {
      "const": "sitla-collection-agency/1"
    }
  },
  "required": [
    "id",
    "profile",
    "authorizationId",
    "agent",
    "processor",
    "sellerId",
    "seller",
    "processorAccount",
    "livemode",
    "currency",
    "feeBasisPoints",
    "refundPolicy",
    "scope",
    "authorizedAt",
    "approvalDigest",
    "approval",
    "limitations",
    "policy"
  ],
  "additionalProperties": false
}
