{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tune.toys/schemas/platform/post.schema.json",
  "title": "PostContent",
  "description": "Author-supplied content of a review, comment or reply. Server-owned fields (author, verified owner, root, depth, pins, state) are not part of it. Replies inherit subject and team scope from their root.",
  "oneOf": [
    {
      "$ref": "#/$defs/ReviewPostContent"
    },
    {
      "$ref": "#/$defs/CommentPostContent"
    },
    {
      "$ref": "#/$defs/ReplyPostContent"
    }
  ],
  "$defs": {
    "PostSubject": {
      "title": "PostSubject",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "type": {
          "$ref": "enums.schema.json#/$defs/PostSubjectType"
        },
        "id": {
          "$ref": "common.schema.json#/$defs/EntityId"
        }
      },
      "required": ["type", "id"]
    },
    "PostAnchor": {
      "title": "PostAnchor",
      "description": "Durable anchor into the published release (public) or current draft (team).",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "definitionId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "nodeId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "frameId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "widgetId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        }
      },
      "minProperties": 1,
      "dependentRequired": {
        "nodeId": ["definitionId"],
        "widgetId": ["frameId"]
      }
    },
    "ReviewPostContent": {
      "title": "ReviewPostContent",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "kind": {
          "const": "review"
        },
        "subject": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "type": {
              "const": "product"
            },
            "id": {
              "$ref": "common.schema.json#/$defs/EntityId"
            }
          },
          "required": ["type", "id"]
        },
        "rating": {
          "type": "integer",
          "minimum": 1,
          "maximum": 5
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "bodyMd": {
          "type": "string",
          "maxLength": 8192
        },
        "reviewedVersionId": {
          "$ref": "common.schema.json#/$defs/EntityId"
        }
      },
      "required": ["kind", "subject", "rating"]
    },
    "CommentPostContent": {
      "title": "CommentPostContent",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "kind": {
          "const": "comment"
        },
        "subject": {
          "$ref": "#/$defs/PostSubject"
        },
        "bodyMd": {
          "type": "string",
          "minLength": 1,
          "maxLength": 8192
        },
        "anchor": {
          "$ref": "#/$defs/PostAnchor"
        },
        "teamOnly": {
          "type": "boolean"
        }
      },
      "required": ["kind", "subject", "bodyMd"],
      "if": {
        "properties": {
          "teamOnly": {
            "const": true
          }
        },
        "required": ["teamOnly"]
      },
      "then": {
        "properties": {
          "subject": {
            "type": "object",
            "properties": {
              "type": {
                "const": "project"
              }
            }
          }
        }
      }
    },
    "ReplyPostContent": {
      "title": "ReplyPostContent",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "kind": {
          "const": "reply"
        },
        "parentId": {
          "$ref": "common.schema.json#/$defs/EntityId"
        },
        "bodyMd": {
          "type": "string",
          "minLength": 1,
          "maxLength": 8192
        }
      },
      "required": ["kind", "parentId", "bodyMd"]
    }
  }
}
