{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://electricblaze.com/developer/instagram-feed/schema.json",
  "title": "ElectricBlaze feed, schema version 1",
  "description": "One shape for every source. Fields a renderer needs are required; platform-specific data lives in raw. Types: https://github.com/ElectricBlaze/electricblaze/blob/main/schema/feed.d.ts",
  "type": "object",
  "required": [
    "schemaVersion",
    "source",
    "origin",
    "posts",
    "fetchedAt",
    "demo"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "source": {
      "type": "string",
      "minLength": 1,
      "description": "instagram, youtube, tiktok, facebook, pinterest, vimeo, twitch, x, or a future source"
    },
    "origin": {
      "$ref": "#/$defs/Origin"
    },
    "posts": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Post"
      }
    },
    "fetchedAt": {
      "type": "string",
      "format": "date-time",
      "description": "When ElectricBlaze fetched this from the platform"
    },
    "demo": {
      "type": "boolean",
      "description": "True until an account is connected; show a small \"demo feed\" label"
    },
    "nextCursor": {
      "type": "string",
      "minLength": 1,
      "description": "Present when more posts can be requested"
    }
  },
  "$defs": {
    "Origin": {
      "type": "object",
      "required": [
        "kind",
        "id",
        "name",
        "displayName",
        "url"
      ],
      "properties": {
        "kind": {
          "enum": [
            "profile",
            "hashtag",
            "playlist",
            "board",
            "channel"
          ]
        },
        "id": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "description": "Handle without \"@\", playlist id, board slug, hashtag without \"#\""
        },
        "displayName": {
          "type": "string",
          "minLength": 1
        },
        "url": {
          "type": "string",
          "pattern": "^https?://"
        },
        "avatarUrl": {
          "type": "string",
          "pattern": "^https?://"
        }
      }
    },
    "Media": {
      "type": "object",
      "required": [
        "url",
        "mime"
      ],
      "properties": {
        "url": {
          "type": "string",
          "pattern": "^https?://"
        },
        "mime": {
          "type": "string",
          "pattern": "^(image|video|audio)/"
        },
        "width": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "height": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "durationSec": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "alt": {
          "type": "string"
        }
      }
    },
    "Link": {
      "type": "object",
      "required": [
        "url"
      ],
      "properties": {
        "url": {
          "type": "string",
          "pattern": "^https?://"
        },
        "title": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "imageUrl": {
          "type": "string",
          "pattern": "^https?://"
        },
        "domain": {
          "type": "string"
        }
      }
    },
    "Stats": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "likes": {
          "type": "number",
          "minimum": 0
        },
        "comments": {
          "type": "number",
          "minimum": 0
        },
        "views": {
          "type": "number",
          "minimum": 0
        },
        "shares": {
          "type": "number",
          "minimum": 0
        }
      }
    },
    "Post": {
      "type": "object",
      "required": [
        "id",
        "source",
        "type",
        "format",
        "status",
        "url",
        "text",
        "media",
        "publishedAt"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "source": {
          "type": "string",
          "minLength": 1
        },
        "type": {
          "enum": [
            "image",
            "video",
            "carousel",
            "text",
            "link"
          ],
          "description": "What to render"
        },
        "format": {
          "type": "string",
          "minLength": 1,
          "description": "What the platform calls it: instagram post | reel. Filters and badges only, never layout"
        },
        "status": {
          "enum": [
            "published",
            "live",
            "upcoming"
          ]
        },
        "url": {
          "type": "string",
          "pattern": "^https?://"
        },
        "text": {
          "type": "string",
          "description": "Caption, description or title; may be empty"
        },
        "media": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Media"
          }
        },
        "thumbnailUrl": {
          "type": "string",
          "pattern": "^https?://"
        },
        "embedUrl": {
          "type": "string",
          "pattern": "^https?://"
        },
        "aspectRatio": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "durationSec": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "link": {
          "$ref": "#/$defs/Link"
        },
        "publishedAt": {
          "type": "string",
          "format": "date-time"
        },
        "stats": {
          "$ref": "#/$defs/Stats"
        },
        "raw": {
          "description": "Original platform payload, untouched"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "enum": [
                  "image",
                  "video",
                  "carousel"
                ]
              }
            }
          },
          "then": {
            "required": [
              "thumbnailUrl"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "link"
              }
            }
          },
          "then": {
            "required": [
              "link"
            ]
          }
        }
      ]
    }
  }
}
