{
  "openapi": "3.1.0",
  "info": {
    "title": "WorkBooth Integration API",
    "version": "1",
    "description": "Cabins, bookings and cabin control for your company. Authentication: company API key (Authorization: Bearer wbk_…). Guide: https://docs.workinbooth.com/en/guide/api"
  },
  "servers": [
    {
      "url": "https://{host}/api",
      "variables": {
        "host": {
          "default": "dashboard.example.com"
        }
      }
    }
  ],
  "paths": {
    "/v1/cabins": {
      "get": {
        "tags": [
          "Integration API v1"
        ],
        "summary": "Кабины компании ключа",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/V1Cabin"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Нет или неверный ключ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/cabins/{id}": {
      "get": {
        "tags": [
          "Integration API v1"
        ],
        "summary": "Кабина и её состояние",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/V1Cabin"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Кабины нет в компании ключа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/cabins/{id}/light": {
      "post": {
        "tags": [
          "Integration API v1"
        ],
        "summary": "Свет: яркость и лампа (право control)",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Кабина выполнила команду",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1ControlResult"
                }
              }
            }
          },
          "403": {
            "description": "У ключа нет права control",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "404": {
            "description": "Кабины нет",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "409": {
            "description": "Кабина не на связи",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "422": {
            "description": "Неверные значения"
          },
          "504": {
            "description": "Кабина не ответила за 5 с",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/V1LightRequest"
              }
            }
          }
        }
      }
    },
    "/v1/cabins/{id}/fan": {
      "post": {
        "tags": [
          "Integration API v1"
        ],
        "summary": "Скорость вентилятора (право control)",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Кабина выполнила команду",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1ControlResult"
                }
              }
            }
          },
          "403": {
            "description": "У ключа нет права control",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "404": {
            "description": "Кабины нет",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "409": {
            "description": "Кабина не на связи",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "422": {
            "description": "Неверные значения"
          },
          "504": {
            "description": "Кабина не ответила за 5 с",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/V1FanRequest"
              }
            }
          }
        }
      }
    },
    "/v1/cabins/{id}/lock": {
      "post": {
        "tags": [
          "Integration API v1"
        ],
        "summary": "Закрыть замок (право control)",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Кабина выполнила команду",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1ControlResult"
                }
              }
            }
          },
          "403": {
            "description": "У ключа нет права control",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "404": {
            "description": "Кабины нет",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "409": {
            "description": "Кабина не на связи",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "422": {
            "description": "Неверные значения"
          },
          "504": {
            "description": "Кабина не ответила за 5 с",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/cabins/{id}/unlock": {
      "post": {
        "tags": [
          "Integration API v1"
        ],
        "summary": "Открыть замок (право control)",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Кабина выполнила команду",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1ControlResult"
                }
              }
            }
          },
          "403": {
            "description": "У ключа нет права control",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "404": {
            "description": "Кабины нет",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "409": {
            "description": "Кабина не на связи",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "422": {
            "description": "Неверные значения"
          },
          "504": {
            "description": "Кабина не ответила за 5 с",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/cabins/{id}/bookings": {
      "get": {
        "tags": [
          "Integration API v1"
        ],
        "summary": "Брони кабины за окно (право bookings)",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/V1Booking"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Кабины нет",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "422": {
            "description": "Неверное окно",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Integration API v1"
        ],
        "summary": "Создать бронь (право bookings)",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/V1BookingCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Создана",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/V1Booking"
                    }
                  }
                }
              }
            }
          },
          "200": {
            "description": "Повтор с тем же external_id",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/V1Booking"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Время занято",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "422": {
            "description": "Неверные значения"
          }
        }
      }
    },
    "/v1/bookings/{booking}": {
      "get": {
        "tags": [
          "Integration API v1"
        ],
        "summary": "Бронь",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "booking",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/V1Booking"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Брони нет в компании ключа",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Integration API v1"
        ],
        "summary": "Изменить время или тему",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "booking",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/V1BookingUpdate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/V1Booking"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Время занято или бронь закрыта",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          },
          "422": {
            "description": "Неверные значения",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Integration API v1"
        ],
        "summary": "Отменить бронь",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "booking",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Отменена",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/V1Booking"
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Бронь уже закрыта",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/V1Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "V1Booking": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "cabin": {
            "$ref": "#/components/schemas/V1CabinRef"
          },
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "confirmed",
              "active",
              "completed",
              "no_show",
              "cancelled",
              "conflict"
            ]
          },
          "source": {
            "type": "string"
          },
          "subject": {
            "type": [
              "string",
              "null"
            ]
          },
          "organizer_email": {
            "type": [
              "string",
              "null"
            ]
          },
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "V1BookingCreate": {
        "type": "object",
        "required": [
          "starts_at",
          "ends_at"
        ],
        "properties": {
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "subject": {
            "type": "string",
            "maxLength": 255
          },
          "organizer_email": {
            "type": "string",
            "format": "email"
          },
          "external_id": {
            "type": "string",
            "maxLength": 200,
            "description": "повтор с тем же значением вернёт ту же бронь"
          }
        }
      },
      "V1BookingUpdate": {
        "type": "object",
        "properties": {
          "starts_at": {
            "type": "string",
            "format": "date-time"
          },
          "ends_at": {
            "type": "string",
            "format": "date-time"
          },
          "subject": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "V1Cabin": {
        "allOf": [
          {
            "$ref": "#/components/schemas/V1CabinRef"
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "address": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "online": {
                "type": "boolean"
              },
              "last_seen_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "mode": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "sleep",
                  "wait",
                  "work",
                  "work_api",
                  null
                ]
              },
              "occupied": {
                "type": [
                  "boolean",
                  "null"
                ]
              },
              "light": {
                "type": "object",
                "properties": {
                  "brightness": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "lamp": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "enum": [
                      "top",
                      "front",
                      null
                    ]
                  }
                }
              },
              "fan": {
                "type": "object",
                "properties": {
                  "speed": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  }
                }
              },
              "entry_sign": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "free",
                  "busy",
                  null
                ]
              },
              "lock": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "locked",
                  "unlocked",
                  null
                ],
                "description": "последняя команда замку с момента запуска кабины"
              },
              "firmware": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        ]
      },
      "V1CabinRef": {
        "type": "object",
        "required": [
          "id",
          "serial",
          "name"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "serial": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      },
      "V1ControlResult": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "cabin": {
                "$ref": "#/components/schemas/V1CabinRef"
              },
              "applied": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        }
      },
      "V1Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "examples": [
                  "unauthorized",
                  "forbidden",
                  "not_found",
                  "cabin_offline",
                  "no_response",
                  "slot_taken",
                  "booking_closed",
                  "invalid_booking",
                  "invalid_window"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "V1FanRequest": {
        "type": "object",
        "required": [
          "speed"
        ],
        "properties": {
          "speed": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          }
        }
      },
      "V1LightRequest": {
        "type": "object",
        "description": "нужно хотя бы одно поле",
        "properties": {
          "brightness": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "lamp": {
            "type": "string",
            "enum": [
              "top",
              "front"
            ]
          }
        }
      }
    },
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Ключ API компании: Authorization: Bearer wbk_… (или заголовок X-Api-Key)"
      }
    }
  }
}
