{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ad-verb.org/schema/adcard-0.1.schema.json",
  "title": "Ad+Card Protocol Draft 0.1",
  "description": "Strict object shapes for Declaration, Offer, and Receipt objects in the Ad+Card 0.1 community draft.",
  "oneOf": [
    {
      "$ref": "#/$defs/declaration"
    },
    {
      "$ref": "#/$defs/offer"
    },
    {
      "$ref": "#/$defs/receipt"
    }
  ],
  "$defs": {
    "spec": {
      "const": "adcard/0.1"
    },
    "uuid": {
      "type": "string",
      "format": "uuid"
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "nullableTimestamp": {
      "oneOf": [
        {
          "$ref": "#/$defs/timestamp"
        },
        {
          "type": "null"
        }
      ]
    },
    "signature": {
      "type": "string",
      "minLength": 1,
      "maxLength": 8192,
      "description": "Reserved draft signature representation. Draft 0.1 does not freeze a signature suite."
    },
    "assurance": {
      "enum": [
        "verified",
        "corroborated",
        "selfAttested",
        "inconclusive"
      ]
    },
    "declaration": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "spec",
        "kind",
        "id",
        "subject",
        "goal",
        "category",
        "createdAt",
        "expiresAt",
        "visibility",
        "signature"
      ],
      "properties": {
        "spec": {
          "$ref": "#/$defs/spec"
        },
        "kind": {
          "const": "declaration"
        },
        "id": {
          "$ref": "#/$defs/uuid"
        },
        "subject": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "description": "A pseudonymous per-card key identifier by default."
        },
        "goal": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "category": {
          "enum": [
            "move",
            "learn",
            "make",
            "connect",
            "restore",
            "explore",
            "serve"
          ]
        },
        "createdAt": {
          "$ref": "#/$defs/timestamp"
        },
        "expiresAt": {
          "$ref": "#/$defs/nullableTimestamp"
        },
        "baseline": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "vibeForecast": {
              "type": "integer",
              "minimum": 0,
              "maximum": 1000
            },
            "note": {
              "type": "string",
              "maxLength": 500
            }
          },
          "minProperties": 1
        },
        "visibility": {
          "enum": [
            "private",
            "link",
            "public"
          ]
        },
        "signature": {
          "$ref": "#/$defs/signature"
        }
      }
    },
    "outfitter": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "id"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512
        }
      }
    },
    "disclosure": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "goal",
        "uses",
        "stored",
        "shared",
        "validates",
        "reward",
        "expiresAt"
      ],
      "properties": {
        "goal": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "uses": {
          "$ref": "#/$defs/disclosureList"
        },
        "stored": {
          "$ref": "#/$defs/disclosureList"
        },
        "shared": {
          "$ref": "#/$defs/disclosureList"
        },
        "validates": {
          "$ref": "#/$defs/disclosureList"
        },
        "reward": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "expiresAt": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "disclosureList": {
      "type": "array",
      "maxItems": 50,
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 500
      }
    },
    "module": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "revision",
        "disclosure"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "revision": {
          "type": "integer",
          "minimum": 1
        },
        "disclosure": {
          "$ref": "#/$defs/disclosure"
        }
      }
    },
    "settlement": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "perReceipt",
        "escrow"
      ],
      "properties": {
        "perReceipt": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "class",
            "amount"
          ],
          "properties": {
            "class": {
              "enum": [
                "verified",
                "corroborated"
              ]
            },
            "amount": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            }
          }
        },
        "escrow": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "pool",
            "attestation"
          ],
          "properties": {
            "pool": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512
            },
            "attestation": {
              "type": "string",
              "minLength": 1,
              "maxLength": 8192
            }
          }
        }
      }
    },
    "offer": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "spec",
        "kind",
        "id",
        "declarationRef",
        "outfitter",
        "equips",
        "module",
        "expiresAt",
        "signature"
      ],
      "properties": {
        "spec": {
          "$ref": "#/$defs/spec"
        },
        "kind": {
          "const": "offer"
        },
        "id": {
          "$ref": "#/$defs/uuid"
        },
        "declarationRef": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512
        },
        "outfitter": {
          "$ref": "#/$defs/outfitter"
        },
        "equips": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1000
        },
        "module": {
          "$ref": "#/$defs/module"
        },
        "settlement": {
          "$ref": "#/$defs/settlement"
        },
        "expiresAt": {
          "$ref": "#/$defs/timestamp"
        },
        "signature": {
          "$ref": "#/$defs/signature"
        }
      }
    },
    "validator": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "version"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        }
      }
    },
    "phase": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "phaseId",
        "claim",
        "assurance",
        "validator"
      ],
      "properties": {
        "phaseId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "claim": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
        },
        "assurance": {
          "$ref": "#/$defs/assurance"
        },
        "validator": {
          "$ref": "#/$defs/validator"
        }
      }
    },
    "window": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "acceptedAt",
        "settledAt"
      ],
      "properties": {
        "acceptedAt": {
          "$ref": "#/$defs/timestamp"
        },
        "settledAt": {
          "$ref": "#/$defs/timestamp"
        }
      }
    },
    "instrument": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "attestation"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "attestation": {
          "oneOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 16384
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "receipt": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "spec",
        "kind",
        "id",
        "declarationRef",
        "offerRef",
        "moduleId",
        "moduleRevision",
        "outcome",
        "phases",
        "window",
        "instrument",
        "signature",
        "subjectSignature"
      ],
      "properties": {
        "spec": {
          "$ref": "#/$defs/spec"
        },
        "kind": {
          "const": "receipt"
        },
        "id": {
          "$ref": "#/$defs/uuid"
        },
        "declarationRef": {
          "oneOf": [
            {
              "$ref": "#/$defs/uuid"
            },
            {
              "type": "null"
            }
          ]
        },
        "offerRef": {
          "oneOf": [
            {
              "$ref": "#/$defs/uuid"
            },
            {
              "type": "null"
            }
          ]
        },
        "moduleId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "moduleRevision": {
          "type": "integer",
          "minimum": 1
        },
        "outcome": {
          "enum": [
            "completed",
            "stopped"
          ]
        },
        "phases": {
          "type": "array",
          "minItems": 1,
          "maxItems": 100,
          "items": {
            "$ref": "#/$defs/phase"
          }
        },
        "window": {
          "$ref": "#/$defs/window"
        },
        "instrument": {
          "$ref": "#/$defs/instrument"
        },
        "signature": {
          "$ref": "#/$defs/signature"
        },
        "subjectSignature": {
          "$ref": "#/$defs/signature"
        }
      }
    }
  }
}
