{
  "openapi": "3.1.0",
  "info": {
    "title": "Cafe Guide API",
    "version": "1.0.0",
    "description": "咖啡馆探店手册数据 API，支持列表、详情、新增、更新和删除。"
  },
  "servers": [
    {
      "url": "https://cafe-guide-api.pages.dev"
    }
  ],
  "paths": {
    "/api/items": {
      "get": {
        "summary": "获取咖啡馆列表",
        "parameters": [
          {
            "name": "city",
            "in": "query",
            "schema": { "type": "string" },
            "description": "按城市筛选"
          },
          {
            "name": "type",
            "in": "query",
            "schema": { "type": "string" },
            "description": "按咖啡类型筛选"
          },
          {
            "name": "q",
            "in": "query",
            "schema": { "type": "string" },
            "description": "关键词搜索"
          }
        ],
        "responses": {
          "200": {
            "description": "咖啡馆列表",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ItemListResponse" }
              }
            }
          }
        }
      },
      "post": {
        "summary": "新增咖啡馆记录",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ItemInput" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "新增成功",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ItemResponse" }
              }
            }
          },
          "400": {
            "description": "请求格式错误"
          }
        }
      }
    },
    "/api/items/{id}": {
      "get": {
        "summary": "获取单条咖啡馆记录",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "咖啡馆详情",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ItemResponse" }
              }
            }
          },
          "404": {
            "description": "记录不存在"
          }
        }
      },
      "put": {
        "summary": "更新咖啡馆记录",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ItemInput" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "更新成功",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ItemResponse" }
              }
            }
          },
          "404": {
            "description": "记录不存在"
          }
        }
      },
      "delete": {
        "summary": "删除咖啡馆记录",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "删除成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "id": { "type": "string" }
                  }
                }
              }
            }
          },
          "404": {
            "description": "记录不存在"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Item": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "city": { "type": "string" },
          "district": { "type": "string" },
          "location": { "type": "string" },
          "types": {
            "type": "array",
            "items": { "type": "string" }
          },
          "score": { "type": "number" },
          "tags": {
            "type": "array",
            "items": { "type": "string" }
          },
          "drink": { "type": "string" },
          "flavor": { "type": "string" },
          "bestFor": { "type": "string" },
          "advice": { "type": "string" }
        },
        "required": ["id", "name", "city", "types", "score"]
      },
      "ItemInput": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "city": { "type": "string" },
          "district": { "type": "string" },
          "location": { "type": "string" },
          "types": {
            "type": "array",
            "items": { "type": "string" }
          },
          "score": { "type": "number" },
          "tags": {
            "type": "array",
            "items": { "type": "string" }
          },
          "drink": { "type": "string" },
          "flavor": { "type": "string" },
          "bestFor": { "type": "string" },
          "advice": { "type": "string" }
        }
      },
      "ItemResponse": {
        "type": "object",
        "properties": {
          "item": { "$ref": "#/components/schemas/Item" }
        }
      },
      "ItemListResponse": {
        "type": "object",
        "properties": {
          "count": { "type": "number" },
          "items": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Item" }
          }
        }
      }
    }
  }
}
