{
  "openapi": "3.0.3",
  "info": {
    "title": "북셀 API",
    "description": "AI 시대의 전자책 마켓플레이스 API. 자동 등록 및 판매 관리 지원. AI 에이전트, 자동화 도구와 쉽게 연동할 수 있습니다.",
    "version": "1.0.0",
    "contact": {
      "name": "북셀 지원팀",
      "email": "support@booksell.kr",
      "url": "https://booksell-kr.vercel.app"
    }
  },
  "servers": [
    {
      "url": "https://booksell-kr.vercel.app/api",
      "description": "프로덕션 서버"
    },
    {
      "url": "http://localhost:3000/api",
      "description": "개발 서버"
    }
  ],
  "tags": [
    {
      "name": "ebooks",
      "description": "전자책 CRUD API"
    },
    {
      "name": "auth",
      "description": "인증 API"
    },
    {
      "name": "upload",
      "description": "파일 업로드 API"
    },
    {
      "name": "my-books",
      "description": "내 책장 API"
    }
  ],
  "paths": {
    "/ebooks": {
      "get": {
        "tags": ["ebooks"],
        "summary": "전자책 목록 조회",
        "description": "승인된 전자책 목록을 조회합니다. 페이지네이션, 카테고리 필터, 검색을 지원합니다.",
        "operationId": "getEbooks",
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "description": "페이지 번호 (1부터 시작)",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "페이지당 항목 수 (최대 100)",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "category",
            "in": "query",
            "description": "카테고리 필터",
            "schema": {
              "type": "string",
              "enum": ["경제/금융", "자기계발", "건강/의학", "취미/실용", "IT/프로그래밍", "인문/사회", "소설/에세이", "기타"]
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "제목/설명 검색어",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "성공",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EbookListResponse"
                }
              }
            }
          },
          "500": {
            "description": "서버 오류",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": ["ebooks"],
        "summary": "전자책 등록",
        "description": "새 전자책을 등록합니다. 판매자 권한이 필요합니다. 등록 후 검토 과정을 거쳐 승인됩니다.",
        "operationId": "createEbook",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateEbookRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "등록 성공"
          },
          "400": {
            "description": "잘못된 요청"
          },
          "401": {
            "description": "인증 필요"
          },
          "403": {
            "description": "권한 없음"
          }
        }
      }
    },
    "/ebooks/{id}": {
      "get": {
        "tags": ["ebooks"],
        "summary": "전자책 상세 조회",
        "description": "특정 전자책의 상세 정보와 리뷰를 조회합니다.",
        "operationId": "getEbookById",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "전자책 ID (UUID)",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "성공"
          },
          "404": {
            "description": "전자책을 찾을 수 없음"
          }
        }
      }
    },
    "/upload": {
      "post": {
        "tags": ["upload"],
        "summary": "파일 업로드",
        "description": "PDF 또는 커버 이미지를 업로드합니다.",
        "operationId": "uploadFile",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "업로드할 파일"
                  },
                  "type": {
                    "type": "string",
                    "enum": ["pdf", "cover"],
                    "description": "파일 유형"
                  }
                },
                "required": ["file", "type"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "업로드 성공",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "description": "업로드된 파일 URL"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "인증 필요"
          }
        }
      }
    },
    "/auth/signup": {
      "post": {
        "tags": ["auth"],
        "summary": "회원가입",
        "description": "새 사용자 계정을 생성합니다.",
        "operationId": "signup",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "password", "name"],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string",
                    "minLength": 6
                  },
                  "name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "가입 성공"
          },
          "400": {
            "description": "잘못된 요청"
          }
        }
      }
    },
    "/auth/login": {
      "post": {
        "tags": ["auth"],
        "summary": "로그인",
        "description": "이메일과 비밀번호로 로그인합니다.",
        "operationId": "login",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "password"],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "password": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "로그인 성공"
          },
          "401": {
            "description": "인증 실패"
          }
        }
      }
    },
    "/auth/me": {
      "get": {
        "tags": ["auth"],
        "summary": "현재 사용자 정보",
        "description": "로그인한 사용자의 정보를 조회합니다.",
        "operationId": "getCurrentUser",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "성공",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          },
          "401": {
            "description": "인증 필요"
          }
        }
      }
    },
    "/my-books": {
      "get": {
        "tags": ["my-books"],
        "summary": "내 책장 목록",
        "description": "구매/대여한 전자책 목록을 조회합니다.",
        "operationId": "getMyBooks",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "성공"
          },
          "401": {
            "description": "인증 필요"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Supabase Auth JWT 토큰"
      }
    },
    "schemas": {
      "Ebook": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string",
            "description": "전자책 제목"
          },
          "description": {
            "type": "string",
            "description": "전자책 설명"
          },
          "category": {
            "type": "string",
            "description": "카테고리"
          },
          "tags": {
            "type": "array",
            "items": { "type": "string" },
            "description": "태그 목록"
          },
          "cover_url": {
            "type": "string",
            "nullable": true,
            "description": "표지 이미지 URL"
          },
          "page_count": {
            "type": "integer",
            "description": "페이지 수"
          },
          "price_rent_7": {
            "type": "integer",
            "description": "7일 대여 가격 (원)"
          },
          "price_rent_30": {
            "type": "integer",
            "description": "30일 대여 가격 (원)"
          },
          "price_buy": {
            "type": "integer",
            "description": "영구 구매 가격 (원)"
          },
          "rating": {
            "type": "number",
            "description": "평균 평점 (0-5)"
          },
          "reviews_count": {
            "type": "integer",
            "description": "리뷰 수"
          },
          "view_count": {
            "type": "integer",
            "description": "조회수"
          },
          "seller": {
            "$ref": "#/components/schemas/Seller"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "EbookListResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "data": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Ebook" }
          },
          "total": { "type": "integer" },
          "page": { "type": "integer" },
          "limit": { "type": "integer" },
          "totalPages": { "type": "integer" }
        }
      },
      "CreateEbookRequest": {
        "type": "object",
        "required": ["title", "description", "category", "pdf_url"],
        "properties": {
          "title": {
            "type": "string",
            "minLength": 2,
            "maxLength": 100,
            "description": "전자책 제목 (2-100자)"
          },
          "description": {
            "type": "string",
            "minLength": 10,
            "maxLength": 5000,
            "description": "전자책 설명 (10-5000자)"
          },
          "category": {
            "type": "string",
            "description": "카테고리"
          },
          "tags": {
            "type": "array",
            "items": { "type": "string" },
            "maxItems": 10,
            "description": "태그 목록 (최대 10개)"
          },
          "pdf_url": {
            "type": "string",
            "description": "PDF 파일 URL"
          },
          "cover_url": {
            "type": "string",
            "description": "표지 이미지 URL"
          },
          "page_count": {
            "type": "integer",
            "description": "페이지 수"
          },
          "price_rent_7": {
            "type": "integer",
            "default": 2900,
            "description": "7일 대여 가격 (기본값: 2900)"
          },
          "price_rent_30": {
            "type": "integer",
            "default": 4900,
            "description": "30일 대여 가격 (기본값: 4900)"
          },
          "price_buy": {
            "type": "integer",
            "default": 7900,
            "description": "영구 구매 가격 (기본값: 7900)"
          }
        }
      },
      "Seller": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "avatar_url": { "type": "string", "nullable": true }
        }
      },
      "User": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "email": { "type": "string", "format": "email" },
          "name": { "type": "string" },
          "role": {
            "type": "string",
            "enum": ["buyer", "seller", "admin"]
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string" }
        }
      }
    }
  }
}
