{
  "openapi": "3.1.0",
  "info": {
    "title": "Antonomus AI API",
    "version": "3.0.0",
    "description": "AI business assistant API — chat, appointment booking, and business management for Polish service companies.",
    "contact": {
      "email": "antonomusai@gmail.com"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://antonomus.com/api",
      "description": "Production"
    }
  ],
  "paths": {
    "/chat": {
      "post": {
        "summary": "Send message to AI assistant",
        "description": "Sends a user message to the AI assistant for a given business. Returns a reply and optionally books an appointment.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message"
                ],
                "properties": {
                  "message": {
                    "type": "string",
                    "description": "User message in Polish"
                  },
                  "business_id": {
                    "type": "string",
                    "description": "Business slug (omit to use default)"
                  },
                  "session_id": {
                    "type": "string",
                    "description": "Conversation session ID (omit to start new)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "AI reply",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "session_id": {
                      "type": "string"
                    },
                    "reply": {
                      "type": "string"
                    },
                    "goodbye": {
                      "type": "boolean"
                    },
                    "appointment": {
                      "$ref": "#/components/schemas/Appointment"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/chat/stream": {
      "post": {
        "summary": "Streaming AI chat (SSE)",
        "description": "Same as /chat but returns Server-Sent Events for real-time streaming.",
        "requestBody": {
          "$ref": "#/components/requestBodies/ChatRequest"
        },
        "responses": {
          "200": {
            "description": "SSE stream",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/businesses/{id}": {
      "get": {
        "summary": "Get business details",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Business details"
          }
        }
      }
    },
    "/appointments/slots": {
      "get": {
        "summary": "Get available time slots",
        "parameters": [
          {
            "in": "query",
            "name": "business_id",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "date",
            "required": true,
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "in": "query",
            "name": "service",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Available slots array"
          }
        }
      }
    },
    "/appointments": {
      "post": {
        "summary": "Book appointment",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "business_id",
                  "service",
                  "date",
                  "time",
                  "client_name"
                ],
                "properties": {
                  "business_id": {
                    "type": "string"
                  },
                  "service": {
                    "type": "string"
                  },
                  "date": {
                    "type": "string",
                    "format": "date"
                  },
                  "time": {
                    "type": "string",
                    "pattern": "^[0-9]{2}:[0-9]{2}$"
                  },
                  "client_name": {
                    "type": "string"
                  },
                  "client_phone": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Appointment created"
          }
        }
      }
    },
    "/onboarding": {
      "post": {
        "summary": "Register new business",
        "description": "Creates a business account with AI assistant. Returns widget snippet.",
        "responses": {
          "201": {
            "description": "Business created with widget snippet"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "BusinessSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "services": {
            "type": "integer"
          }
        }
      },
      "Appointment": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "service": {
            "type": "string"
          },
          "date": {
            "type": "string"
          },
          "time": {
            "type": "string"
          },
          "client_name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "confirmed",
              "cancelled"
            ]
          }
        }
      }
    },
    "requestBodies": {
      "ChatRequest": {
        "required": true,
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "message"
              ],
              "properties": {
                "message": {
                  "type": "string"
                },
                "business_id": {
                  "type": "string"
                },
                "session_id": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}
