{
  "openapi": "3.1.0",
  "info": {
    "title": "Evimarko API",
    "version": "1.0.0",
    "summary": "API of Evimarko — CRM for car detailing, car service, tire shops and car washes.",
    "description": "Read services, clients, cars, bookings and orders of a studio, create clients, book a free time and get events on a webhook.\n\n**Key.** The studio owner creates it in Evimarko: Settings → Integrations → For developers → API keys. A key is shown once and belongs to one studio. Send it in the header `Authorization: Bearer dos_…`. A key has one of two rights: *Only look* (GET requests and webhooks) or *Look and add* (also create clients and bookings).\n\n**Limits.** 120 requests a minute per key; 30 a minute for creating clients, bookings and webhooks. Over the limit — 429 with `Retry-After`.\n\n**Formats.** JSON. Money — integers in minor units (`total_minor: 12500` = 125.00) with a currency code. Times — ISO 8601 in UTC. Errors — `{\"message\": \"…\"}`, and for 422 also `errors` by field.\n\n**What the API never does.** It takes no payments and deletes no studio data.",
    "contact": {
      "name": "Evimarko",
      "url": "https://evimarko.com/developers"
    }
  },
  "servers": [
    {
      "url": "https://evimarko.com/api/v1"
    }
  ],
  "externalDocs": {
    "description": "Guide for developers",
    "url": "https://evimarko.com/developers"
  },
  "security": [
    {
      "bearerKey": []
    }
  ],
  "tags": [
    {
      "name": "Studio"
    },
    {
      "name": "Services"
    },
    {
      "name": "Clients"
    },
    {
      "name": "Vehicles"
    },
    {
      "name": "Bookings and orders"
    },
    {
      "name": "Webhooks"
    },
    {
      "name": "Accounting",
      "description": "For accounting software: payments, materials, stock, expenses (read only)."
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "tags": [
          "Studio"
        ],
        "operationId": "getMe",
        "summary": "The studio of the key (also the way to test a key)",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "studio": {
                      "$ref": "#/components/schemas/Studio"
                    },
                    "key": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string"
                        },
                        "scope": {
                          "type": "string",
                          "enum": [
                            "read",
                            "write"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          }
        }
      }
    },
    "/services": {
      "get": {
        "tags": [
          "Services"
        ],
        "operationId": "listServices",
        "summary": "List services",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "How many rows.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "after_id",
            "in": "query",
            "required": false,
            "description": "Rows with a bigger id (from `next_after_id`).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "description": "Only rows changed since this moment.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "order",
            "in": "query",
            "required": false,
            "description": "desc — newest first (paging with after_id works only with asc).",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "asc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Service"
                      }
                    },
                    "next_after_id": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Pass it as `after_id` to get the next portion; null — no more rows."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/services/{id}": {
      "get": {
        "tags": [
          "Services"
        ],
        "operationId": "getService",
        "summary": "Get a service",
        "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/Service"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/clients": {
      "get": {
        "tags": [
          "Clients"
        ],
        "operationId": "listClients",
        "summary": "List clients or find one by phone",
        "parameters": [
          {
            "name": "phone",
            "in": "query",
            "required": false,
            "description": "Find by phone. Any format: the last 9 digits are compared.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "How many rows.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "after_id",
            "in": "query",
            "required": false,
            "description": "Rows with a bigger id (from `next_after_id`).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "description": "Only rows changed since this moment.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "order",
            "in": "query",
            "required": false,
            "description": "desc — newest first (paging with after_id works only with asc).",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "asc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Client"
                      }
                    },
                    "next_after_id": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Pass it as `after_id` to get the next portion; null — no more rows."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      },
      "post": {
        "tags": [
          "Clients"
        ],
        "operationId": "createClient",
        "summary": "Create a client",
        "description": "Needs a key with the right **Read and write**. If a client with the same phone exists, it is returned (200, `created: false`) and nothing changes.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewClient"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Client"
                    },
                    "created": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "200": {
            "description": "A client with this phone already exists",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Client"
                    },
                    "created": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/clients/{id}": {
      "get": {
        "tags": [
          "Clients"
        ],
        "operationId": "getClient",
        "summary": "Get a client",
        "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/Client"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/clients/{id}/vehicles": {
      "get": {
        "tags": [
          "Vehicles"
        ],
        "operationId": "listClientVehicles",
        "summary": "Cars of a client",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Vehicle"
                      }
                    },
                    "next_after_id": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Pass it as `after_id` to get the next portion; null — no more rows."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/vehicles": {
      "get": {
        "tags": [
          "Vehicles"
        ],
        "operationId": "listVehicles",
        "summary": "List cars",
        "parameters": [
          {
            "name": "client_id",
            "in": "query",
            "required": false,
            "description": "Cars of one client.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "plate",
            "in": "query",
            "required": false,
            "description": "Find by plate number.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "How many rows.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "after_id",
            "in": "query",
            "required": false,
            "description": "Rows with a bigger id (from `next_after_id`).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "description": "Only rows changed since this moment.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "order",
            "in": "query",
            "required": false,
            "description": "desc — newest first (paging with after_id works only with asc).",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "asc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Vehicle"
                      }
                    },
                    "next_after_id": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Pass it as `after_id` to get the next portion; null — no more rows."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/vehicles/{id}": {
      "get": {
        "tags": [
          "Vehicles"
        ],
        "operationId": "getVehicle",
        "summary": "Get a car",
        "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/Vehicle"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/orders": {
      "get": {
        "tags": [
          "Bookings and orders"
        ],
        "operationId": "listOrders",
        "summary": "List bookings and orders",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "Only this status.",
            "schema": {
              "type": "string",
              "enum": [
                "scheduled",
                "arrived",
                "in_progress",
                "ready",
                "delivered",
                "cancelled"
              ]
            }
          },
          {
            "name": "client_id",
            "in": "query",
            "required": false,
            "description": "Orders of one client.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "starts_from",
            "in": "query",
            "required": false,
            "description": "Start time not earlier than.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "starts_to",
            "in": "query",
            "required": false,
            "description": "Start time not later than.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "How many rows.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "after_id",
            "in": "query",
            "required": false,
            "description": "Rows with a bigger id (from `next_after_id`).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "description": "Only rows changed since this moment.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "order",
            "in": "query",
            "required": false,
            "description": "desc — newest first (paging with after_id works only with asc).",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "asc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Order"
                      }
                    },
                    "next_after_id": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Pass it as `after_id` to get the next portion; null — no more rows."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/orders/{id}": {
      "get": {
        "tags": [
          "Bookings and orders"
        ],
        "operationId": "getOrder",
        "summary": "Get a booking or order (its status)",
        "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/Order"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/slots": {
      "get": {
        "tags": [
          "Bookings and orders"
        ],
        "operationId": "listSlots",
        "summary": "Free times of a day",
        "description": "The same free times the studio's booking page shows: working hours, busy bays and masters, minimum notice.",
        "parameters": [
          {
            "name": "date",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "services",
            "in": "query",
            "required": true,
            "description": "Service ids: `services=12,15` or `services[]=12&services[]=15`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "size",
            "in": "query",
            "required": false,
            "description": "Car size.",
            "schema": {
              "type": "string",
              "enum": [
                "small",
                "medium",
                "large",
                "suv"
              ],
              "default": "medium"
            }
          },
          {
            "name": "visit",
            "in": "query",
            "required": false,
            "description": "Hybrid studios: true — a visit to the client.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "branch_id",
            "in": "query",
            "required": false,
            "description": "Required when the studio has several branches.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "date": {
                      "type": "string",
                      "format": "date"
                    },
                    "timezone": {
                      "type": "string"
                    },
                    "duration_minutes": {
                      "type": "integer"
                    },
                    "slots": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "examples": [
                        [
                          "10:00",
                          "11:00",
                          "14:30"
                        ]
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/bookings": {
      "post": {
        "tags": [
          "Bookings and orders"
        ],
        "operationId": "createBooking",
        "summary": "Book a free time",
        "description": "Needs a key with the right **Read and write**. Works like the studio's booking page: the time must be free, the client is found by phone or created, the staff get their usual notice and the client the usual confirmation. A taken time, a day off or a second identical booking answer 422.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewBooking"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Booked",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Order"
                    },
                    "client_created": {
                      "type": "boolean"
                    },
                    "deposit_url": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "uri",
                      "description": "Where the client pays the deposit, if the studio takes one."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "listWebhooks",
        "summary": "List webhooks",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Webhook"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          }
        }
      },
      "post": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "subscribeWebhook",
        "summary": "Subscribe to events (REST hook)",
        "description": "Works with any key, also read-only. The `secret` for checking signatures is in the answer once.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewWebhook"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Subscribed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/Webhook"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "secret": {
                              "type": "string"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/webhooks/{id}": {
      "delete": {
        "tags": [
          "Webhooks"
        ],
        "operationId": "unsubscribeWebhook",
        "summary": "Unsubscribe",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "description": "Only webhooks added through the API.",
        "responses": {
          "204": {
            "description": "Unsubscribed"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/payments": {
      "get": {
        "tags": [
          "Accounting"
        ],
        "operationId": "listPayments",
        "summary": "List payments",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "How many rows.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "after_id",
            "in": "query",
            "required": false,
            "description": "Rows with a bigger id (from `next_after_id`).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "description": "Only rows changed since this moment.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "order",
            "in": "query",
            "required": false,
            "description": "desc — newest first (paging with after_id works only with asc).",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "asc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Payment"
                      }
                    },
                    "next_after_id": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Pass it as `after_id` to get the next portion; null — no more rows."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/payments/{id}": {
      "get": {
        "tags": [
          "Accounting"
        ],
        "operationId": "getPayment",
        "summary": "Get a payment",
        "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/Payment"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/materials": {
      "get": {
        "tags": [
          "Accounting"
        ],
        "operationId": "listMaterials",
        "summary": "List materials",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "How many rows.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "after_id",
            "in": "query",
            "required": false,
            "description": "Rows with a bigger id (from `next_after_id`).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "description": "Only rows changed since this moment.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "order",
            "in": "query",
            "required": false,
            "description": "desc — newest first (paging with after_id works only with asc).",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "asc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Material"
                      }
                    },
                    "next_after_id": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Pass it as `after_id` to get the next portion; null — no more rows."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/materials/{id}": {
      "get": {
        "tags": [
          "Accounting"
        ],
        "operationId": "getMaterial",
        "summary": "Get a material",
        "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/Material"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/stock-movements": {
      "get": {
        "tags": [
          "Accounting"
        ],
        "operationId": "listStockMovements",
        "summary": "List stock movements",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "How many rows.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "after_id",
            "in": "query",
            "required": false,
            "description": "Rows with a bigger id (from `next_after_id`).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "description": "Only rows changed since this moment.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "order",
            "in": "query",
            "required": false,
            "description": "desc — newest first (paging with after_id works only with asc).",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "asc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/StockMovement"
                      }
                    },
                    "next_after_id": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Pass it as `after_id` to get the next portion; null — no more rows."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/stock-movements/{id}": {
      "get": {
        "tags": [
          "Accounting"
        ],
        "operationId": "getStockMovement",
        "summary": "Get a stock movement",
        "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/StockMovement"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/expenses": {
      "get": {
        "tags": [
          "Accounting"
        ],
        "operationId": "listExpenses",
        "summary": "List expenses",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "How many rows.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "after_id",
            "in": "query",
            "required": false,
            "description": "Rows with a bigger id (from `next_after_id`).",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "updated_since",
            "in": "query",
            "required": false,
            "description": "Only rows changed since this moment.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "order",
            "in": "query",
            "required": false,
            "description": "desc — newest first (paging with after_id works only with asc).",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "asc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Expense"
                      }
                    },
                    "next_after_id": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Pass it as `after_id` to get the next portion; null — no more rows."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "422": {
            "$ref": "#/components/responses/Invalid"
          }
        }
      }
    },
    "/expenses/{id}": {
      "get": {
        "tags": [
          "Accounting"
        ],
        "operationId": "getExpense",
        "summary": "Get an expense",
        "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/Expense"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooMany"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  },
  "webhooks": {
    "booking.created": {
      "post": {
        "summary": "A new booking (from the booking page, a bot, the API or the CRM)",
        "operationId": "onBookingCreated",
        "description": "Headers: `X-Evimarko-Event`, `X-Evimarko-Delivery`, `X-Evimarko-Signature: sha256=<HMAC-SHA256 of the raw body with the webhook secret>`. Answer 2xx within 10 seconds. Other answers are retried after 1, 5, 30 minutes, 2 and 6 hours. `410 Gone` unsubscribes at once; 30 failed deliveries in a row switch the webhook off.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEvent"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "event": {
                        "const": "booking.created"
                      },
                      "data": {
                        "$ref": "#/components/schemas/Order"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    },
    "order.status_changed": {
      "post": {
        "summary": "The status of an order changed",
        "operationId": "onOrderStatusChanged",
        "description": "Headers: `X-Evimarko-Event`, `X-Evimarko-Delivery`, `X-Evimarko-Signature: sha256=<HMAC-SHA256 of the raw body with the webhook secret>`. Answer 2xx within 10 seconds. Other answers are retried after 1, 5, 30 minutes, 2 and 6 hours. `410 Gone` unsubscribes at once; 30 failed deliveries in a row switch the webhook off.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEvent"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "event": {
                        "const": "order.status_changed"
                      },
                      "data": {
                        "allOf": [
                          {
                            "$ref": "#/components/schemas/Order"
                          },
                          {
                            "type": "object",
                            "properties": {
                              "previous_status": {
                                "type": "string",
                                "enum": [
                                  "scheduled",
                                  "arrived",
                                  "in_progress",
                                  "ready",
                                  "delivered",
                                  "cancelled"
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    },
    "order.ready": {
      "post": {
        "summary": "The car is ready",
        "operationId": "onOrderReady",
        "description": "Headers: `X-Evimarko-Event`, `X-Evimarko-Delivery`, `X-Evimarko-Signature: sha256=<HMAC-SHA256 of the raw body with the webhook secret>`. Answer 2xx within 10 seconds. Other answers are retried after 1, 5, 30 minutes, 2 and 6 hours. `410 Gone` unsubscribes at once; 30 failed deliveries in a row switch the webhook off.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEvent"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "event": {
                        "const": "order.ready"
                      },
                      "data": {
                        "$ref": "#/components/schemas/Order"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    },
    "order.delivered": {
      "post": {
        "summary": "The order is delivered to the client (a sale)",
        "operationId": "onOrderDelivered",
        "description": "Headers: `X-Evimarko-Event`, `X-Evimarko-Delivery`, `X-Evimarko-Signature: sha256=<HMAC-SHA256 of the raw body with the webhook secret>`. Answer 2xx within 10 seconds. Other answers are retried after 1, 5, 30 minutes, 2 and 6 hours. `410 Gone` unsubscribes at once; 30 failed deliveries in a row switch the webhook off.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEvent"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "event": {
                        "const": "order.delivered"
                      },
                      "data": {
                        "$ref": "#/components/schemas/Order"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    },
    "client.created": {
      "post": {
        "summary": "A new client",
        "operationId": "onClientCreated",
        "description": "Headers: `X-Evimarko-Event`, `X-Evimarko-Delivery`, `X-Evimarko-Signature: sha256=<HMAC-SHA256 of the raw body with the webhook secret>`. Answer 2xx within 10 seconds. Other answers are retried after 1, 5, 30 minutes, 2 and 6 hours. `410 Gone` unsubscribes at once; 30 failed deliveries in a row switch the webhook off.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEvent"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "event": {
                        "const": "client.created"
                      },
                      "data": {
                        "$ref": "#/components/schemas/Client"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    },
    "payment.created": {
      "post": {
        "summary": "A payment",
        "operationId": "onPaymentCreated",
        "description": "Headers: `X-Evimarko-Event`, `X-Evimarko-Delivery`, `X-Evimarko-Signature: sha256=<HMAC-SHA256 of the raw body with the webhook secret>`. Answer 2xx within 10 seconds. Other answers are retried after 1, 5, 30 minutes, 2 and 6 hours. `410 Gone` unsubscribes at once; 30 failed deliveries in a row switch the webhook off.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEvent"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "event": {
                        "const": "payment.created"
                      },
                      "data": {
                        "$ref": "#/components/schemas/Payment"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    },
    "material.purchased": {
      "post": {
        "summary": "A material purchase",
        "operationId": "onMaterialPurchased",
        "description": "Headers: `X-Evimarko-Event`, `X-Evimarko-Delivery`, `X-Evimarko-Signature: sha256=<HMAC-SHA256 of the raw body with the webhook secret>`. Answer 2xx within 10 seconds. Other answers are retried after 1, 5, 30 minutes, 2 and 6 hours. `410 Gone` unsubscribes at once; 30 failed deliveries in a row switch the webhook off.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEvent"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "event": {
                        "const": "material.purchased"
                      },
                      "data": {
                        "$ref": "#/components/schemas/StockMovement"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    },
    "expense.created": {
      "post": {
        "summary": "An expense",
        "operationId": "onExpenseCreated",
        "description": "Headers: `X-Evimarko-Event`, `X-Evimarko-Delivery`, `X-Evimarko-Signature: sha256=<HMAC-SHA256 of the raw body with the webhook secret>`. Answer 2xx within 10 seconds. Other answers are retried after 1, 5, 30 minutes, 2 and 6 hours. `410 Gone` unsubscribes at once; 30 failed deliveries in a row switch the webhook off.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/WebhookEvent"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "event": {
                        "const": "expense.created"
                      },
                      "data": {
                        "$ref": "#/components/schemas/Expense"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key of the studio: `Authorization: Bearer dos_…`"
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "No key, a wrong key or a revoked key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Forbidden": {
        "description": "The studio has no access, or the key is read-only and the request creates something (402 — the API is not in the studio's plan)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "No such row in this studio",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Invalid": {
        "description": "The data did not pass the check; see `errors`",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "TooMany": {
        "description": "Too many requests; wait `Retry-After` seconds",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "message"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "What went wrong, in English."
          },
          "errors": {
            "type": "object",
            "description": "Only for 422: field name → list of messages.",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      },
      "Studio": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "currency": {
            "type": "string",
            "examples": [
              "EUR"
            ]
          },
          "timezone": {
            "type": "string",
            "examples": [
              "Europe/Sofia"
            ]
          },
          "country": {
            "type": "string",
            "examples": [
              "BG"
            ]
          },
          "business_type": {
            "type": [
              "string",
              "null"
            ],
            "description": "studio — clients come to the studio; mobile — the master drives to the client; hybrid — both."
          },
          "booking_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "Public booking page of the studio (null when online booking is off)."
          },
          "branches": {
            "type": "array",
            "description": "Filled only when the studio has several branches. Then `branch_id` is required in GET /slots and POST /bookings.",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "name": {
                  "type": "string"
                },
                "address": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          }
        }
      },
      "Client": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "source": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Vehicle": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "client_id": {
            "type": "integer"
          },
          "make": {
            "type": [
              "string",
              "null"
            ]
          },
          "model": {
            "type": [
              "string",
              "null"
            ]
          },
          "year": {
            "type": [
              "integer",
              "null"
            ]
          },
          "color": {
            "type": [
              "string",
              "null"
            ]
          },
          "paint_code": {
            "type": [
              "string",
              "null"
            ]
          },
          "plate": {
            "type": [
              "string",
              "null"
            ]
          },
          "vin": {
            "type": [
              "string",
              "null"
            ]
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Service": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "category": {
            "type": [
              "string",
              "null"
            ]
          },
          "unit": {
            "type": "string"
          },
          "is_active": {
            "type": "boolean"
          },
          "online_booking": {
            "type": "boolean",
            "description": "true — the service can be used in GET /slots and POST /bookings."
          },
          "prices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "vehicle_size": {
                  "type": "string",
                  "enum": [
                    "small",
                    "medium",
                    "large",
                    "suv"
                  ]
                },
                "price_minor": {
                  "type": "integer",
                  "description": "Price in minor units (cents)."
                },
                "duration_minutes": {
                  "type": "integer"
                }
              }
            }
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "OrderItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "service_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "name": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "price_minor": {
            "type": "integer"
          },
          "kind": {
            "type": "string",
            "enum": [
              "service",
              "part"
            ]
          }
        }
      },
      "Order": {
        "type": "object",
        "description": "An order. A booking is an order with the status `scheduled`.",
        "properties": {
          "id": {
            "type": "integer"
          },
          "number": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "enum": [
              "scheduled",
              "arrived",
              "in_progress",
              "ready",
              "delivered",
              "cancelled"
            ]
          },
          "client_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "vehicle_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "starts_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "UTC."
          },
          "ends_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "UTC."
          },
          "delivered_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "source": {
            "type": [
              "string",
              "null"
            ],
            "description": "online — the client booked (booking page, bot, API); staff — created in the CRM."
          },
          "on_site": {
            "type": "boolean",
            "description": "true — a visit to the client's address."
          },
          "address": {
            "type": [
              "string",
              "null"
            ]
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "currency": {
            "type": "string"
          },
          "subtotal_minor": {
            "type": "integer"
          },
          "discount_minor": {
            "type": "integer"
          },
          "tax_minor": {
            "type": "integer"
          },
          "total_minor": {
            "type": "integer"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderItem"
            }
          },
          "client": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Client"
              },
              {
                "type": "null"
              }
            ]
          },
          "vehicle": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Vehicle"
              },
              {
                "type": "null"
              }
            ]
          },
          "client_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "\"My booking\" page for the client: status, studio contacts."
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Payment": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "order_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "invoice_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "amount_minor": {
            "type": "integer"
          },
          "fee_minor": {
            "type": "integer"
          },
          "currency": {
            "type": [
              "string",
              "null"
            ]
          },
          "method": {
            "type": "string"
          },
          "is_deposit": {
            "type": "boolean"
          },
          "reference": {
            "type": [
              "string",
              "null"
            ]
          },
          "paid_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Material": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "unit": {
            "type": "string"
          },
          "is_paint": {
            "type": "boolean"
          },
          "package_size_milli": {
            "type": [
              "integer",
              "null"
            ]
          },
          "package_cost_minor": {
            "type": [
              "integer",
              "null"
            ]
          },
          "stock_milli": {
            "type": "integer",
            "description": "Stock in thousandths of the unit."
          },
          "is_active": {
            "type": "boolean"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "StockMovement": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "material_id": {
            "type": "integer"
          },
          "material": {
            "type": [
              "string",
              "null"
            ]
          },
          "unit": {
            "type": [
              "string",
              "null"
            ]
          },
          "type": {
            "type": "string"
          },
          "qty_milli": {
            "type": "integer"
          },
          "cost_minor": {
            "type": [
              "integer",
              "null"
            ]
          },
          "supplier": {
            "type": [
              "string",
              "null"
            ]
          },
          "order_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Expense": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "month": {
            "type": "string",
            "examples": [
              "2026-11"
            ]
          },
          "category": {
            "type": "string"
          },
          "amount_minor": {
            "type": "integer"
          },
          "note": {
            "type": [
              "string",
              "null"
            ]
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Webhook": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "booking.created",
                "order.status_changed",
                "order.ready",
                "order.delivered",
                "payment.created",
                "material.purchased",
                "expense.created",
                "client.created"
              ]
            }
          },
          "is_active": {
            "type": "boolean",
            "description": "false — switched off after many failed deliveries or because its key was revoked."
          },
          "source": {
            "type": "string",
            "enum": [
              "api",
              "manual"
            ],
            "description": "api — added through this API; manual — typed by the owner in Settings (cannot be deleted through the API)."
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "NewClient": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 255
          },
          "phone": {
            "type": "string",
            "maxLength": 40
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "notes": {
            "type": "string",
            "maxLength": 2000
          }
        }
      },
      "NewBooking": {
        "type": "object",
        "required": [
          "services",
          "name",
          "phone"
        ],
        "description": "Give the time as `date` + `time` (the studio's own clock) or as `starts_at`.",
        "properties": {
          "services": {
            "description": "Ids of services with `online_booking: true`. An array, or text \"12,15\".",
            "oneOf": [
              {
                "type": "array",
                "items": {
                  "type": "integer"
                },
                "minItems": 1,
                "maxItems": 20
              },
              {
                "type": "string"
              }
            ]
          },
          "date": {
            "type": "string",
            "format": "date",
            "examples": [
              "2026-12-01"
            ]
          },
          "time": {
            "type": "string",
            "examples": [
              "10:00"
            ],
            "description": "HH:MM, studio time. Must be one of GET /slots."
          },
          "starts_at": {
            "type": "string",
            "format": "date-time",
            "description": "Instead of date + time. ISO 8601 with a zone.",
            "examples": [
              "2026-12-01T10:00:00+02:00"
            ]
          },
          "size": {
            "type": "string",
            "enum": [
              "small",
              "medium",
              "large",
              "suv"
            ],
            "default": "medium",
            "description": "Car size — it changes price and duration."
          },
          "name": {
            "type": "string",
            "maxLength": 255,
            "description": "Client name."
          },
          "phone": {
            "type": "string",
            "description": "Client phone, 9–15 digits. A known phone books the existing client."
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "make": {
            "type": "string",
            "maxLength": 60
          },
          "model": {
            "type": "string",
            "maxLength": 60
          },
          "plate": {
            "type": "string",
            "maxLength": 20
          },
          "comment": {
            "type": "string",
            "maxLength": 2000
          },
          "visit": {
            "type": "boolean",
            "description": "Only for studios of type hybrid: true — a visit to the client."
          },
          "address": {
            "type": "string",
            "maxLength": 255,
            "description": "Required for a visit."
          },
          "address_to": {
            "type": "string",
            "maxLength": 255,
            "description": "Tow truck: where to take the car."
          },
          "quantities": {
            "type": "object",
            "description": "For services counted in pieces or hours: service id → quantity.",
            "additionalProperties": {
              "type": "number"
            }
          },
          "branch_id": {
            "type": "integer",
            "description": "Required when the studio has several branches (GET /me → studio.branches)."
          }
        }
      },
      "NewWebhook": {
        "type": "object",
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Public https address. Local and internal addresses are refused."
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "booking.created",
                "order.status_changed",
                "order.ready",
                "order.delivered",
                "payment.created",
                "material.purchased",
                "expense.created",
                "client.created"
              ]
            },
            "minItems": 1
          },
          "event": {
            "type": "string",
            "enum": [
              "booking.created",
              "order.status_changed",
              "order.ready",
              "order.delivered",
              "payment.created",
              "material.purchased",
              "expense.created",
              "client.created"
            ],
            "description": "One event instead of `events`."
          }
        }
      },
      "WebhookEvent": {
        "type": "object",
        "description": "Body we POST to your address.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Id of the delivery. The same id comes again on a retry — use it to skip duplicates."
          },
          "event": {
            "type": "string",
            "enum": [
              "booking.created",
              "order.status_changed",
              "order.ready",
              "order.delivered",
              "payment.created",
              "material.purchased",
              "expense.created",
              "client.created",
              "ping"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "data": {
            "type": "object",
            "description": "The object of the event: an Order (booking.created, order.*; order.status_changed also has `previous_status`), a Client, a Payment, a StockMovement or an Expense."
          }
        }
      }
    }
  }
}
