{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "AI Daywire edition input",
  "type": "object",
  "required": [
    "schemaVersion",
    "editionId",
    "title",
    "dek",
    "coverageNote",
    "summaryIntro",
    "items",
    "sources",
    "review",
    "corrections"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "editionId": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}(-adult)?$"
    },
    "title": {
      "type": "string",
      "minLength": 10,
      "maxLength": 220
    },
    "dek": {
      "type": "string",
      "minLength": 20,
      "maxLength": 500
    },
    "coverageNote": {
      "type": "string",
      "minLength": 15,
      "maxLength": 700
    },
    "summaryIntro": {
      "type": "string",
      "minLength": 20,
      "maxLength": 1500
    },
    "publishedAt": {
      "type": "string",
      "format": "date-time"
    },
    "items": {
      "type": "array",
      "minItems": 1,
      "maxItems": 8,
      "items": {
        "$ref": "#/$defs/story"
      }
    },
    "sources": {
      "type": "array",
      "minItems": 1,
      "maxItems": 40,
      "items": {
        "$ref": "#/$defs/source"
      }
    },
    "review": {
      "type": "object",
      "required": [
        "passed",
        "reviewedAt",
        "method"
      ],
      "properties": {
        "passed": {
          "const": true
        },
        "reviewedAt": {
          "type": "string",
          "format": "date-time"
        },
        "method": {
          "const": "source-check"
        }
      }
    },
    "corrections": {
      "type": "array",
      "maxItems": 30,
      "items": {
        "type": "object",
        "required": [
          "date",
          "note"
        ],
        "properties": {
          "date": {
            "type": "string",
            "format": "date-time"
          },
          "note": {
            "type": "string",
            "minLength": 10,
            "maxLength": 1000
          }
        }
      }
    },
    "audience": {
      "const": "adult",
      "description": "Omit for general editions. Adult requires YYYY-MM-DD-adult ID."
    }
  },
  "$defs": {
    "refs": {
      "type": "array",
      "minItems": 1,
      "maxItems": 12,
      "items": {
        "type": "string",
        "maxLength": 32
      }
    },
    "source": {
      "type": "object",
      "required": [
        "id",
        "title",
        "publisher",
        "url",
        "publishedDate",
        "kind"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$",
          "maxLength": 32
        },
        "title": {
          "type": "string",
          "minLength": 3,
          "maxLength": 250
        },
        "publisher": {
          "type": "string",
          "minLength": 2,
          "maxLength": 100
        },
        "url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        },
        "publishedDate": {
          "type": [
            "string",
            "null"
          ],
          "format": "date"
        },
        "kind": {
          "type": "string",
          "minLength": 3,
          "maxLength": 60
        }
      }
    },
    "story": {
      "type": "object",
      "required": [
        "id",
        "title",
        "category",
        "eventDate",
        "status",
        "sourceIds",
        "short",
        "claims",
        "long"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$",
          "minLength": 3,
          "maxLength": 100
        },
        "title": {
          "type": "string",
          "minLength": 8,
          "maxLength": 220
        },
        "category": {
          "enum": [
            "Creativity & Media",
            "Models & Agents",
            "Tools & Applications",
            "Business & Infrastructure",
            "Science & Research",
            "Safety & Society"
          ]
        },
        "eventDate": {
          "type": "string",
          "format": "date"
        },
        "status": {
          "type": "array",
          "minItems": 1,
          "maxItems": 4,
          "items": {
            "enum": [
              "available",
              "announced",
              "company-claim",
              "research-preprint",
              "independently-verified",
              "reported",
              "unconfirmed"
            ]
          }
        },
        "sourceIds": {
          "$ref": "#/$defs/refs"
        },
        "short": {
          "type": "string",
          "minLength": 40,
          "maxLength": 2500
        },
        "claims": {
          "type": "array",
          "minItems": 1,
          "maxItems": 12,
          "items": {
            "type": "object",
            "required": [
              "text",
              "sourceIds"
            ],
            "properties": {
              "text": {
                "type": "string",
                "minLength": 10,
                "maxLength": 1500
              },
              "sourceIds": {
                "$ref": "#/$defs/refs"
              }
            }
          }
        },
        "long": {
          "type": "array",
          "minItems": 1,
          "maxItems": 12,
          "items": {
            "type": "object",
            "required": [
              "text",
              "sourceIds"
            ],
            "properties": {
              "text": {
                "type": "string",
                "minLength": 20,
                "maxLength": 6000
              },
              "sourceIds": {
                "type": "array",
                "maxItems": 12,
                "items": {
                  "type": "string"
                }
              },
              "type": {
                "const": "analysis"
              }
            },
            "allOf": [
              {
                "if": {
                  "not": {
                    "required": [
                      "type"
                    ]
                  }
                },
                "then": {
                  "properties": {
                    "sourceIds": {
                      "minItems": 1
                    }
                  }
                }
              }
            ]
          }
        },
        "kind": {
          "enum": [
            "news",
            "quick-update",
            "guide",
            "rumor"
          ]
        },
        "thumbnail": {
          "$ref": "#/$defs/thumbnail"
        },
        "tags": {
          "type": "array",
          "minItems": 1,
          "maxItems": 3,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": [
              "video",
              "images",
              "audio",
              "coding",
              "models",
              "productivity",
              "business",
              "research",
              "safety",
              "guides"
            ]
          }
        }
      },
      "allOf": [
        {
          "if": {
            "required": [
              "kind"
            ],
            "properties": {
              "kind": {
                "const": "rumor"
              }
            }
          },
          "then": {
            "properties": {
              "status": {
                "contains": {
                  "const": "unconfirmed"
                },
                "not": {
                  "contains": {
                    "enum": [
                      "available",
                      "independently-verified"
                    ]
                  }
                }
              }
            }
          },
          "else": {
            "properties": {
              "status": {
                "not": {
                  "contains": {
                    "const": "unconfirmed"
                  }
                }
              }
            }
          }
        }
      ]
    },
    "thumbnail": {
      "type": "object",
      "required": [
        "src",
        "alt",
        "credit",
        "kind"
      ],
      "properties": {
        "src": {
          "type": "string",
          "maxLength": 500,
          "pattern": "^(/images/thumbnails/[a-z0-9-]+\\.(png|jpg|webp)|/api/media/thumbnails/[0-9]{4}-[0-9]{2}-[0-9]{2}/[a-z0-9-]+/[a-f0-9]{64})$"
        },
        "alt": {
          "type": "string",
          "minLength": 10,
          "maxLength": 300
        },
        "credit": {
          "type": "string",
          "minLength": 3,
          "maxLength": 200
        },
        "kind": {
          "enum": [
            "photo",
            "screenshot",
            "editorial-illustration"
          ]
        },
        "sourceUrl": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://"
        }
      },
      "description": "Optional for archived editions; each new general daily story needs a reviewed thumbnail. Uploaded src must match its edition and story. Never use temporary or external image URLs."
    }
  },
  "allOf": [
    {
      "if": {
        "required": [
          "audience"
        ]
      },
      "then": {
        "properties": {
          "editionId": {
            "pattern": "^\\d{4}-\\d{2}-\\d{2}-adult$"
          }
        }
      },
      "else": {
        "properties": {
          "editionId": {
            "format": "date",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
          }
        }
      }
    }
  ]
}
