{
  "openapi": "3.1.0",
  "info": {
    "title": "ITcode CRM integration API",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://itcode.tech/api/app/workspace/integration/v1"
    }
  ],
  "security": [
    {
      "crmKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "crmKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-CRM-Key"
      }
    }
  },
  "paths": {
    "/event": {
      "post": {
        "summary": "Принять событие",
        "responses": {
          "200": {
            "description": "Подтверждено"
          },
          "400": {
            "description": "Некорректные данные"
          },
          "403": {
            "description": "Нет доступа"
          },
          "409": {
            "description": "Конфликт"
          },
          "429": {
            "description": "Лимит запросов"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "eventId": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9:_-]{1,100}$"
                  },
                  "kind": {
                    "enum": [
                      "client",
                      "message",
                      "catalog"
                    ]
                  },
                  "externalId": {
                    "type": "string"
                  },
                  "threadId": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "contact": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "text": {
                    "type": "string",
                    "maxLength": 4000
                  },
                  "clientId": {
                    "type": "string"
                  },
                  "company": {
                    "type": "string"
                  },
                  "custom": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "string"
                    }
                  },
                  "expectedVersion": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "priceMinor": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "stock": {
                    "type": "number"
                  },
                  "unit": {
                    "type": "string"
                  }
                },
                "required": [
                  "eventId",
                  "kind"
                ],
                "oneOf": [
                  {
                    "properties": {
                      "kind": {
                        "const": "client"
                      }
                    },
                    "required": [
                      "externalId",
                      "name"
                    ]
                  },
                  {
                    "properties": {
                      "kind": {
                        "const": "message"
                      }
                    },
                    "required": [
                      "threadId",
                      "name",
                      "text"
                    ]
                  },
                  {
                    "properties": {
                      "kind": {
                        "const": "catalog"
                      }
                    },
                    "required": [
                      "externalId",
                      "name",
                      "priceMinor",
                      "stock",
                      "expectedVersion"
                    ]
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/outbox": {
      "get": {
        "summary": "Очередь исходящих данного подключения",
        "responses": {
          "200": {
            "description": "Подтверждено"
          },
          "400": {
            "description": "Некорректные данные"
          },
          "403": {
            "description": "Нет доступа"
          },
          "409": {
            "description": "Конфликт"
          },
          "429": {
            "description": "Лимит запросов"
          }
        }
      }
    },
    "/ack": {
      "post": {
        "summary": "Подтвердить отправку или ошибку",
        "responses": {
          "200": {
            "description": "Подтверждено"
          },
          "400": {
            "description": "Некорректные данные"
          },
          "403": {
            "description": "Нет доступа"
          },
          "409": {
            "description": "Конфликт"
          },
          "429": {
            "description": "Лимит запросов"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "state"
                ],
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "state": {
                    "enum": [
                      "delivered",
                      "failed"
                    ]
                  },
                  "providerId": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
