{
  "openapi": "3.0.0",
  "info": {
    "title": "飞鸟农场联系我们API",
    "description": "飞鸟农场网站联系我们模块的API接口文档",
    "version": "1.0.0",
    "contact": {
      "name": "飞鸟农场开发团队",
      "email": "dev@feiniao.com"
    }
  },
  "servers": [
    {
      "url": "http://localhost:3000",
      "description": "开发环境"
    },
    {
      "url": "https://api.feiniao.com",
      "description": "生产环境"
    }
  ],
  "tags": [
    {
      "name": "Contact",
      "description": "联系我们相关接口"
    }
  ],
  "paths": {
    "/contact": {
      "post": {
        "tags": ["Contact"],
        "summary": "提交联系我们表单",
        "description": "用户提交联系我们表单，系统会保存到数据库并发送邮件通知",
        "operationId": "createContact",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateContactRequest"
              },
              "examples": {
                "basic": {
                  "summary": "基本留言",
                  "value": {
                    "name": "张三",
                    "email": "zhangsan@example.com",
                    "subject": "产品咨询",
                    "message": "我想了解一下你们的产品价格和功能特点。"
                  }
                },
                "complete": {
                  "summary": "完整信息",
                  "value": {
                    "name": "李四",
                    "email": "lisi@company.com",
                    "phone": "13800138000",
                    "company": "某某科技有限公司",
                    "subject": "合作洽谈",
                    "message": "我们公司希望与贵公司建立长期合作关系，请提供详细的产品资料和合作方案。"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "留言提交成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuccessResponse"
                },
                "examples": {
                  "success": {
                    "summary": "成功响应",
                    "value": {
                      "success": true,
                      "message": "留言提交成功，我们会尽快回复您",
                      "data": {
                        "id": 1,
                        "message": "感谢您的留言，我们已收到并会在24小时内回复"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "参数验证失败",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "examples": {
                  "validation_error": {
                    "summary": "参数验证失败",
                    "value": {
                      "success": false,
                      "message": "参数验证失败",
                      "error": [
                        "联系人姓名不能为空",
                        "邮箱格式不正确"
                      ]
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务器内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": ["Contact"],
        "summary": "获取联系我们列表",
        "description": "管理员获取联系我们留言列表，支持分页和状态筛选",
        "operationId": "getContacts",
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "description": "页码",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "每页数量",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 10
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "处理状态筛选",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [0, 1],
              "description": "0-未处理，1-已处理"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "获取成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "获取成功"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "contacts": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Contact"
                          }
                        },
                        "pagination": {
                          "$ref": "#/components/schemas/Pagination"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务器内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/contact/{id}": {
      "get": {
        "tags": ["Contact"],
        "summary": "获取联系详情",
        "description": "根据ID获取具体的联系记录详情",
        "operationId": "getContactDetail",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "联系记录ID",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "获取成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "获取成功"
                    },
                    "data": {
                      "$ref": "#/components/schemas/Contact"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "联系记录不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "examples": {
                  "not_found": {
                    "summary": "记录不存在",
                    "value": {
                      "success": false,
                      "message": "联系记录不存在",
                      "error": null
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "服务器内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": ["Contact"],
        "summary": "删除联系记录",
        "description": "根据ID删除联系记录",
        "operationId": "deleteContact",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "联系记录ID",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "删除成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "删除成功"
                    },
                    "data": {
                      "type": "null",
                      "example": null
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "联系记录不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "服务器内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/contact/{id}/status": {
      "put": {
        "tags": ["Contact"],
        "summary": "更新处理状态",
        "description": "更新联系记录的处理状态",
        "operationId": "updateContactStatus",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "联系记录ID",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["status"],
                "properties": {
                  "status": {
                    "type": "integer",
                    "enum": [0, 1],
                    "description": "处理状态：0-未处理，1-已处理"
                  }
                }
              },
              "examples": {
                "mark_processed": {
                  "summary": "标记为已处理",
                  "value": {
                    "status": 1
                  }
                },
                "mark_unprocessed": {
                  "summary": "标记为未处理",
                  "value": {
                    "status": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "状态更新成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "状态更新成功"
                    },
                    "data": {
                      "$ref": "#/components/schemas/Contact"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "状态值无效",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "examples": {
                  "invalid_status": {
                    "summary": "状态值无效",
                    "value": {
                      "success": false,
                      "message": "状态值只能是0或1",
                      "error": null
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "联系记录不存在",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "服务器内部错误",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CreateContactRequest": {
        "type": "object",
        "required": ["name", "email", "subject", "message"],
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 100,
            "description": "联系人姓名",
            "example": "张三"
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 255,
            "description": "联系人邮箱",
            "example": "zhangsan@example.com"
          },
          "phone": {
            "type": "string",
            "maxLength": 20,
            "description": "联系电话",
            "example": "13800138000"
          },
          "company": {
            "type": "string",
            "maxLength": 200,
            "description": "公司名称",
            "example": "某某科技有限公司"
          },
          "subject": {
            "type": "string",
            "maxLength": 200,
            "description": "留言主题",
            "example": "产品咨询"
          },
          "message": {
            "type": "string",
            "description": "留言内容",
            "example": "我想了解一下你们的产品价格和功能特点。"
          }
        }
      },
      "Contact": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "联系记录ID",
            "example": 1
          },
          "name": {
            "type": "string",
            "description": "联系人姓名",
            "example": "张三"
          },
          "email": {
            "type": "string",
            "format": "email",
            "description": "联系人邮箱",
            "example": "zhangsan@example.com"
          },
          "phone": {
            "type": "string",
            "nullable": true,
            "description": "联系电话",
            "example": "13800138000"
          },
          "company": {
            "type": "string",
            "nullable": true,
            "description": "公司名称",
            "example": "某某科技有限公司"
          },
          "subject": {
            "type": "string",
            "description": "留言主题",
            "example": "产品咨询"
          },
          "message": {
            "type": "string",
            "description": "留言内容",
            "example": "我想了解一下你们的产品价格和功能特点。"
          },
          "status": {
            "type": "integer",
            "enum": [0, 1],
            "description": "处理状态：0-未处理，1-已处理",
            "example": 0
          },
          "isEmailSent": {
            "type": "boolean",
            "description": "是否已发送邮件通知",
            "example": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "创建时间",
            "example": "2024-01-15T10:30:00.000Z"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "更新时间",
            "example": "2024-01-15T10:30:00.000Z"
          }
        }
      },
      "Pagination": {
        "type": "object",
        "properties": {
          "total": {
            "type": "integer",
            "description": "总记录数",
            "example": 100
          },
          "page": {
            "type": "integer",
            "description": "当前页码",
            "example": 1
          },
          "limit": {
            "type": "integer",
            "description": "每页数量",
            "example": 10
          },
          "totalPages": {
            "type": "integer",
            "description": "总页数",
            "example": 10
          }
        }
      },
      "SuccessResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "请求状态",
            "example": true
          },
          "message": {
            "type": "string",
            "description": "响应消息",
            "example": "操作成功"
          },
          "data": {
            "type": "object",
            "description": "响应数据"
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "请求状态",
            "example": false
          },
          "message": {
            "type": "string",
            "description": "错误消息",
            "example": "操作失败"
          },
          "error": {
            "type": "object",
            "description": "错误详情",
            "nullable": true
          }
        }
      }
    }
  }
}
