{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:sitla:work-results:1:schema:credential",
  "$comment": "SPDX-License-Identifier: CC0-1.0; unsigned semantics are separate from issuer signature and provider observations.",
  "type": "object",
  "properties": {
    "@context": {
      "type": "array",
      "items": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "object"
          }
        ]
      },
      "minItems": 1
    },
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "type": {
      "type": "array",
      "prefixItems": [
        {
          "const": "VerifiableCredential"
        },
        {
          "const": "urn:sitla:credential:WorkResult:1"
        }
      ],
      "minItems": 2,
      "maxItems": 2
    },
    "issuer": {
      "type": "string",
      "pattern": "^did:sitla:"
    },
    "validFrom": {
      "type": "string",
      "pattern": "^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d(?:\\.\\d{3})?Z$"
    },
    "licenses": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 2048
      }
    },
    "didAllowList": {
      "type": "array",
      "maxItems": 100,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 2048
      }
    },
    "credentialSubject": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^did:sitla:"
        },
        "profile": {
          "const": "sitla-work-result/1"
        },
        "paymentContext": {
          "type": "object",
          "properties": {
            "kind": {
              "enum": [
                "escrow",
                "work"
              ]
            },
            "id": {
              "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}$"
            }
          },
          "required": [
            "kind",
            "id"
          ],
          "additionalProperties": false
        },
        "role": {
          "enum": [
            "buyer",
            "seller"
          ]
        },
        "assertion": {
          "enum": [
            "delivered",
            "accepted"
          ]
        },
        "buyerDid": {
          "type": "string",
          "pattern": "^did:sitla:"
        },
        "sellerDid": {
          "type": "string",
          "pattern": "^did:sitla:"
        },
        "termsDigest": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "jobRequestIds": {
          "type": "array",
          "maxItems": 20,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048
          }
        },
        "performanceDigest": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "amountMinor": {
          "type": "integer",
          "minimum": 500,
          "maximum": 99999999
        },
        "currency": {
          "const": "JPY"
        },
        "currencyExponent": {
          "const": 0
        },
        "summary": {
          "type": "string",
          "maxLength": 500
        },
        "extensions": {
          "type": "object"
        }
      },
      "additionalProperties": false,
      "required": [
        "id",
        "profile",
        "paymentContext",
        "role",
        "assertion",
        "buyerDid",
        "sellerDid",
        "termsDigest",
        "jobRequestIds",
        "performanceDigest",
        "amountMinor",
        "currency",
        "currencyExponent"
      ]
    },
    "credentialStatus": {
      "type": "object"
    }
  },
  "additionalProperties": false,
  "required": [
    "@context",
    "id",
    "type",
    "issuer",
    "validFrom",
    "licenses",
    "didAllowList",
    "credentialSubject"
  ]
}
