{
  "openapi": "3.0.3",
  "info": {
    "title": "GreenTu Law Chat API",
    "version": "1.0.0",
    "description": "보험 손해사정 판례·법령 AI 챗봇 공개 API. 인증 없이 외부 사이트/앱에서 바로 호출 가능. 법제처 OpenAPI 실시간 연동으로 환각을 최소화합니다. 본 API는 정보 제공 목적이며 법률 자문이 아닙니다.",
    "contact": {
      "url": "https://greentu.io/"
    }
  },
  "servers": [
    { "url": "https://api.greentu.io" }
  ],
  "paths": {
    "/api/chat": {
      "post": {
        "summary": "채팅 (SSE 스트리밍)",
        "description": "보험 손해사정 관련 질문에 대한 AI 답변을 SSE(Server-Sent Events) 스트리밍으로 반환합니다.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ChatRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "text/event-stream. 각 이벤트는 data: {\"type\":\"content\"|\"done\"|\"error\", ...} 형태.",
            "content": {
              "text/event-stream": { "schema": { "type": "string" } }
            }
          },
          "400": { "description": "message 필드 누락" },
          "405": { "description": "허용되지 않는 HTTP Method" },
          "429": { "description": "RATE_LIMIT_EXCEEDED — 분당 요청 한도 초과" },
          "500": { "description": "서버 내부 오류" }
        }
      }
    },
    "/api/chat-sync": {
      "post": {
        "summary": "채팅 (JSON 단건 응답)",
        "description": "SSE 파싱이 어려운 환경(모바일 앱, 서버 to 서버)을 위한 단건 JSON 응답 채팅 엔드포인트.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ChatRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/ChatSyncResponse" } }
            }
          },
          "400": { "description": "message 필드 누락" },
          "429": { "description": "RATE_LIMIT_EXCEEDED — 분당 요청 한도 초과" },
          "500": { "description": "서버 내부 오류" }
        }
      }
    },
    "/api/reset": {
      "post": {
        "summary": "세션 초기화",
        "description": "지정한 세션의 대화 히스토리를 초기화합니다.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "session_id": { "type": "string" }
                },
                "required": ["session_id"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "example": "ok" },
                    "message": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "summary": "상태 확인",
        "description": "API 서비스 상태를 확인합니다. 모니터링 및 헬스체크에 사용하세요.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "example": "ok" },
                    "service": { "type": "string", "example": "GreenTu Law Chat API" },
                    "version": { "type": "string", "example": "1.0.0" },
                    "timestamp": { "type": "string", "format": "date-time" },
                    "endpoints": { "type": "array", "items": { "type": "object" } }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ChatRequest": {
        "type": "object",
        "properties": {
          "message": { "type": "string", "description": "사용자 질문 내용" },
          "session_id": { "type": "string", "description": "세션 ID (멀티턴 대화용, 기본값: default)" }
        },
        "required": ["message"]
      },
      "ChatSyncResponse": {
        "type": "object",
        "properties": {
          "status": { "type": "string", "example": "ok" },
          "reply": { "type": "string", "description": "AI 답변 전문 (마크다운)" },
          "usage": {
            "type": "object",
            "properties": {
              "prompt": { "type": "integer" },
              "completion": { "type": "integer" },
              "total": { "type": "integer" }
            }
          },
          "session_id": { "type": "string" },
          "grounding_sources": {
            "type": "array",
            "items": { "type": "string" },
            "example": ["법제처 법령검색 API", "법제처 판례검색 API"]
          }
        }
      }
    }
  }
}
