{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rctp.dev/schemas/listing.schema.json",
  "title": "Listing (subset)",
  "description": "A unique item listing (capability dev.rctp.listing, subset). listing_hash = sha-256 over the JCS of title, category, condition, price, description and attributes. Carries public terms only, never private ones (INV-1).",
  "type": "object",
  "properties": {
    "id": {
      "$ref": "common.schema.json#/$defs/ListingId"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 140
    },
    "category": {
      "type": "string",
      "pattern": "^[a-z0-9-]{1,64}$"
    },
    "condition": {
      "type": "string",
      "enum": [
        "new",
        "like_new",
        "good",
        "fair",
        "for_parts"
      ]
    },
    "price": {
      "$ref": "common.schema.json#/$defs/Money",
      "description": "Public list price"
    },
    "description": {
      "type": "string",
      "maxLength": 5000,
      "description": "Free text from the seller. Never an instruction to the enforcement point (INV-5)."
    },
    "attributes": {
      "type": "object",
      "description": "Structured listing facts; agents answer buyers from these, not from free text (11.3)",
      "propertyNames": {
        "pattern": "^[a-z][a-z0-9_]{0,63}$"
      },
      "additionalProperties": {
        "type": [
          "string",
          "number",
          "boolean"
        ]
      },
      "maxProperties": 50
    },
    "quantity": {
      "const": 1
    },
    "listing_hash": {
      "$ref": "common.schema.json#/$defs/Digest"
    },
    "status": {
      "type": "string",
      "enum": [
        "active",
        "reserved",
        "sold",
        "withdrawn"
      ]
    },
    "term_set": {
      "$ref": "common.schema.json#/$defs/TermSetId",
      "description": "The term set the listing's terms were approved under"
    },
    "terms_commitment": {
      "$ref": "common.schema.json#/$defs/Digest",
      "description": "Present once the seller approved terms"
    },
    "public_terms": {
      "$ref": "common.schema.json#/$defs/PublicTermValues"
    },
    "created_at": {
      "$ref": "common.schema.json#/$defs/Timestamp"
    }
  },
  "additionalProperties": false,
  "required": [
    "id",
    "title",
    "category",
    "condition",
    "price",
    "quantity",
    "listing_hash",
    "status",
    "created_at"
  ],
  "dependentRequired": {
    "terms_commitment": [
      "term_set",
      "public_terms"
    ],
    "public_terms": [
      "terms_commitment"
    ]
  }
}
