{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/akeda-ru/json-schema/akeda-ru-chat-conversation-schema.json",
  "title": "ChatConversation",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/akeda-ru-chat-api-openapi.yml#/components/schemas/ChatConversation",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "type",
    "status",
    "title",
    "description",
    "last_seq",
    "last_message_id",
    "last_message_at",
    "created_at",
    "updated_at",
    "unread_count",
    "first_unread_seq",
    "manual_unread_seq",
    "notification_mode",
    "mention_count"
  ],
  "properties": {
    "id": {
      "$ref": "#/$defs/UUID"
    },
    "type": {
      "type": "string",
      "enum": [
        "direct",
        "group",
        "system"
      ]
    },
    "status": {
      "type": "string",
      "enum": [
        "active",
        "archived"
      ]
    },
    "title": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "last_seq": {
      "type": "integer",
      "format": "int64",
      "minimum": 0
    },
    "last_message_id": {
      "oneOf": [
        {
          "$ref": "#/$defs/UUID"
        },
        {
          "type": "null"
        }
      ]
    },
    "preview": {
      "$ref": "#/$defs/ChatMessage"
    },
    "last_message_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    },
    "capabilities": {
      "$ref": "#/$defs/ChatConversationCapabilities"
    },
    "unread_count": {
      "type": "integer",
      "format": "int64",
      "minimum": 0
    },
    "first_unread_seq": {
      "type": [
        "integer",
        "null"
      ],
      "format": "int64",
      "minimum": 1
    },
    "manual_unread_seq": {
      "type": [
        "integer",
        "null"
      ],
      "format": "int64",
      "minimum": 0
    },
    "notification_mode": {
      "type": "string"
    },
    "notification_muted_until": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "До какого момента беседа молчит, если звук выключен на время: пока срок не вышел, notification_mode = muted. После срока поле пустое, а режим снова прежний"
    },
    "notification_mode_after_mute": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "all",
        "mentions",
        null
      ],
      "description": "Какой режим вернётся, когда выйдет срок «без звука»; есть только пока срок идёт. По нему «Включить звук» возвращает прежний выбор"
    },
    "mention_count": {
      "type": "integer",
      "format": "int64",
      "minimum": 0
    },
    "origin": {
      "type": "string"
    },
    "origin_ref": {
      "oneOf": [
        {
          "$ref": "#/$defs/UUID"
        },
        {
          "type": "null"
        }
      ]
    },
    "last_read_seq": {
      "type": "integer",
      "format": "int64",
      "minimum": 0
    },
    "others_read_seq": {
      "type": "integer",
      "format": "int64",
      "minimum": 0
    },
    "has_avatar": {
      "type": "boolean"
    },
    "avatar_url": {
      "type": "string"
    },
    "peer_user_id": {
      "type": [
        "integer",
        "null"
      ],
      "format": "int64",
      "minimum": 1
    },
    "peer_avatar_url": {
      "type": "string"
    }
  },
  "$defs": {
    "ChatAttachment": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "original_name",
        "content_type",
        "size_bytes",
        "sha256_hex",
        "media_kind",
        "duration_ms",
        "content_url"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/UUID"
        },
        "original_name": {
          "type": "string"
        },
        "content_type": {
          "type": "string",
          "enum": [
            "audio/mp4",
            "audio/webm",
            "audio/ogg",
            "video/mp4",
            "video/quicktime"
          ]
        },
        "size_bytes": {
          "type": "integer",
          "format": "int64",
          "minimum": 1,
          "maximum": 41943040
        },
        "sha256_hex": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "media_kind": {
          "type": "string",
          "enum": [
            "voice",
            "video_circle"
          ]
        },
        "duration_ms": {
          "type": "integer",
          "format": "int64",
          "minimum": 250,
          "maximum": 300000
        },
        "content_url": {
          "type": "string"
        }
      }
    },
    "ChatConversationCapabilities": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "canRead",
        "canWrite",
        "canManageMembers",
        "canUpload",
        "canReact",
        "canPin",
        "canMarkRead",
        "canMarkUnread",
        "canMention",
        "canSetNotificationMode"
      ],
      "properties": {
        "canRead": {
          "type": "boolean"
        },
        "canWrite": {
          "type": "boolean"
        },
        "canManageMembers": {
          "type": "boolean"
        },
        "canUpload": {
          "type": "boolean"
        },
        "canReact": {
          "type": "boolean"
        },
        "canPin": {
          "type": "boolean"
        },
        "canMarkRead": {
          "type": "boolean"
        },
        "canMarkUnread": {
          "type": "boolean"
        },
        "canMention": {
          "type": "boolean"
        },
        "canSetNotificationMode": {
          "type": "boolean"
        },
        "canSendVoice": {
          "type": "boolean",
          "description": "Можно записать голосовое или видеокружок и переслать такое сюда. В чатах задач и поддержки — нет: там только текст, файлы и снимки экрана"
        }
      }
    },
    "ChatMessage": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "conversation_id",
        "seq",
        "sender_user_id",
        "kind",
        "body",
        "mentions",
        "client_message_id",
        "created_at",
        "attachments"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/UUID"
        },
        "conversation_id": {
          "$ref": "#/$defs/UUID"
        },
        "seq": {
          "type": "integer",
          "format": "int64",
          "minimum": 1
        },
        "sender_user_id": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int64"
        },
        "kind": {
          "type": "string",
          "enum": [
            "text",
            "system",
            "application",
            "file"
          ]
        },
        "body": {
          "type": "string"
        },
        "mentions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ChatMessageMention"
          }
        },
        "client_message_id": {
          "oneOf": [
            {
              "$ref": "#/$defs/UUID"
            },
            {
              "type": "null"
            }
          ]
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "attachments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ChatAttachment"
          }
        },
        "reply_to_message_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid"
        },
        "forwarded_from_message_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Пересланное: исходное сообщение. Нет у обычных сообщений"
        },
        "forwarded_from_user_id": {
          "type": "integer",
          "format": "int64",
          "minimum": 1,
          "description": "Пересланное: автор оригинала — участник кабинета (ERP-1964, «Переслано от …»). При пересылке пересланного — тот, кто написал первым. Нет у обычных и у старых пересланных сообщений"
        },
        "forwarded_from_name": {
          "type": "string",
          "maxLength": 512,
          "description": "Пересланное: подпись автора оригинала, когда участника нет в справочнике людей, — имя под ответом поддержки или название исходной беседы. Нет у обычных и у старых пересланных сообщений"
        },
        "reply_quote": {
          "type": "string",
          "description": "Цитата части исходного сообщения; поля нет, когда ответ на сообщение целиком, исходное удалено или недоступно"
        },
        "deleted_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "Надгробие: сообщение удалено у всех. Тела, вложений, упоминаний и реакций у него нет; показывать его в ленте не нужно"
        }
      }
    },
    "ChatMessageMention": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "user_id",
        "display_name"
      ],
      "properties": {
        "user_id": {
          "type": "integer",
          "format": "int64"
        },
        "display_name": {
          "type": "string"
        }
      }
    },
    "UUID": {
      "type": "string",
      "format": "uuid"
    }
  }
}