{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://bsfproject.com/data/schemas/contribution.schema.json",
  "title": "BSF Project contribution intake",
  "description": "Payload posted to POST /api/v1/contributions (review queue; FastAPI backend in /backend).",
  "type": "object",
  "required": ["version", "category", "submittedAt", "payload", "attestation"],
  "additionalProperties": false,
  "properties": {
    "version": { "type": "integer", "const": 1 },
    "category": {
      "type": "string",
      "enum": ["feedback", "bug", "correction", "topic", "article", "source", "design-community"]
    },
    "submittedAt": { "type": "string", "format": "date-time" },
    "contact": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "email": { "type": "string", "format": "email", "maxLength": 254 },
        "name": { "type": "string", "maxLength": 120 }
      }
    },
    "payload": { "$ref": "#/$defs/payload" },
    "attestation": { "$ref": "#/$defs/attestation" },
    "meta": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "pageUrl": { "type": "string", "maxLength": 2048 },
        "referrer": { "type": "string", "maxLength": 2048 }
      }
    }
  },
  "$defs": {
    "attestation": {
      "type": "object",
      "required": ["noSecrets", "humanSubmitter"],
      "additionalProperties": false,
      "properties": {
        "noSecrets": { "type": "boolean", "const": true },
        "humanSubmitter": { "type": "boolean", "const": true },
        "licenseGrant": {
          "type": "boolean",
          "description": "Required true for article, topic, correction, source, and design-community submissions. Not required for feedback or bug."
        }
      }
    },
    "payload": {
      "oneOf": [
        { "$ref": "#/$defs/payloadFeedback" },
        { "$ref": "#/$defs/payloadBug" },
        { "$ref": "#/$defs/payloadCorrection" },
        { "$ref": "#/$defs/payloadTopic" },
        { "$ref": "#/$defs/payloadArticle" },
        { "$ref": "#/$defs/payloadSource" },
        { "$ref": "#/$defs/payloadDesignCommunity" }
      ]
    },
    "payloadFeedback": {
      "type": "object",
      "required": ["message"],
      "additionalProperties": false,
      "properties": {
        "subject": { "type": "string", "maxLength": 200 },
        "message": { "type": "string", "minLength": 20, "maxLength": 4000 }
      }
    },
    "payloadBug": {
      "type": "object",
      "required": ["pageUrl", "description"],
      "additionalProperties": false,
      "properties": {
        "pageUrl": { "type": "string", "maxLength": 2048 },
        "description": { "type": "string", "minLength": 10, "maxLength": 4000 },
        "stepsToReproduce": { "type": "string", "maxLength": 4000 },
        "browser": { "type": "string", "maxLength": 500 }
      }
    },
    "payloadCorrection": {
      "type": "object",
      "required": ["pageUrl", "issue", "suggestedFix"],
      "additionalProperties": false,
      "properties": {
        "pageUrl": { "type": "string", "maxLength": 2048 },
        "issue": { "type": "string", "minLength": 10, "maxLength": 4000 },
        "suggestedFix": { "type": "string", "minLength": 10, "maxLength": 4000 },
        "sourceUrl": { "type": "string", "maxLength": 2048 }
      }
    },
    "payloadTopic": {
      "type": "object",
      "required": ["title", "summary"],
      "additionalProperties": false,
      "properties": {
        "title": { "type": "string", "minLength": 3, "maxLength": 200 },
        "summary": { "type": "string", "minLength": 20, "maxLength": 2000 }
      }
    },
    "payloadArticle": {
      "type": "object",
      "required": ["title", "summary", "body"],
      "additionalProperties": false,
      "properties": {
        "title": { "type": "string", "minLength": 3, "maxLength": 200 },
        "summary": { "type": "string", "minLength": 20, "maxLength": 500 },
        "body": { "type": "string", "minLength": 100, "maxLength": 50000 },
        "topics": {
          "type": "array",
          "items": { "type": "string", "minLength": 1, "maxLength": 60 },
          "maxItems": 12
        },
        "sourceUrls": {
          "type": "array",
          "items": { "type": "string", "maxLength": 2048 },
          "maxItems": 20
        }
      }
    },
    "payloadSource": {
      "type": "object",
      "required": ["title", "url", "whyRelevant"],
      "additionalProperties": false,
      "properties": {
        "title": { "type": "string", "minLength": 3, "maxLength": 500 },
        "url": { "type": "string", "maxLength": 2048 },
        "doi": { "type": "string", "maxLength": 120 },
        "whyRelevant": { "type": "string", "minLength": 20, "maxLength": 2000 },
        "licenseNotes": { "type": "string", "maxLength": 1000 }
      }
    },
    "payloadDesignCommunity": {
      "type": "object",
      "required": ["kind", "title", "summary"],
      "additionalProperties": false,
      "properties": {
        "kind": { "type": "string", "enum": ["design", "community"] },
        "title": { "type": "string", "minLength": 3, "maxLength": 200 },
        "location": { "type": "string", "maxLength": 200 },
        "summary": { "type": "string", "minLength": 20, "maxLength": 4000 },
        "linkUrls": {
          "type": "array",
          "items": { "type": "string", "maxLength": 2048 },
          "maxItems": 10
        }
      }
    }
  }
}
