openapi: 3.0.0
info:
  title: 参保申请管理API
  description: 保险系统参保申请功能相关API接口文档
  version: 1.0.0
  contact:
    name: 开发团队
    email: dev@example.com

servers:
  - url: http://localhost:3000/api
    description: 开发环境

paths:
  /insurance/applications:
    get:
      summary: 获取参保申请列表
      description: 分页获取参保申请列表，支持多种筛选条件
      tags:
        - 参保申请
      security:
        - bearerAuth: []
      parameters:
        - name: page
          in: query
          description: 页码
          required: false
          schema:
            type: integer
            default: 1
            minimum: 1
        - name: limit
          in: query
          description: 每页数量
          required: false
          schema:
            type: integer
            default: 10
            minimum: 1
            maximum: 100
        - name: application_no
          in: query
          description: 申请单号（模糊搜索）
          required: false
          schema:
            type: string
        - name: name
          in: query
          description: 投保人姓名（模糊搜索）
          required: false
          schema:
            type: string
        - name: status
          in: query
          description: 申请状态
          required: false
          schema:
            type: string
            enum: [pending, initial_approved, under_review, approved, rejected, paid]
        - name: insurance_type_name
          in: query
          description: 参保险种名称（模糊搜索）
          required: false
          schema:
            type: string
        - name: insurance_category
          in: query
          description: 参保类型（模糊搜索）
          required: false
          schema:
            type: string
        - name: dateRange[start]
          in: query
          description: 申请时间范围开始
          required: false
          schema:
            type: string
            format: date
        - name: dateRange[end]
          in: query
          description: 申请时间范围结束
          required: false
          schema:
            type: string
            format: date
      responses:
        '200':
          description: 获取成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: "获取保险申请列表成功"
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/InsuranceApplication'
                  pagination:
                    $ref: '#/components/schemas/Pagination'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'

    post:
      summary: 创建参保申请
      description: 创建新的参保申请
      tags:
        - 参保申请
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateInsuranceApplicationRequest'
      responses:
        '201':
          description: 创建成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: "保险申请创建成功"
                  data:
                    $ref: '#/components/schemas/InsuranceApplication'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'

  /insurance/applications/{id}:
    get:
      summary: 获取参保申请详情
      description: 根据ID获取单个参保申请的详细信息
      tags:
        - 参保申请
      security:
        - bearerAuth: []
      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/InsuranceApplication'
        '404':
          $ref: '#/components/responses/NotFound'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'

    put:
      summary: 更新参保申请
      description: 更新参保申请信息
      tags:
        - 参保申请
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          description: 申请ID
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateInsuranceApplicationRequest'
      responses:
        '200':
          description: 更新成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: "保险申请更新成功"
                  data:
                    $ref: '#/components/schemas/InsuranceApplication'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'

    delete:
      summary: 删除参保申请
      description: 删除指定的参保申请
      tags:
        - 参保申请
      security:
        - bearerAuth: []
      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: "保险申请删除成功"
        '404':
          $ref: '#/components/responses/NotFound'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'

  /insurance/applications/{id}/review:
    patch:
      summary: 审核参保申请
      description: 对参保申请进行审核操作
      tags:
        - 参保申请
      security:
        - bearerAuth: []
      parameters:
        - name: id
          in: path
          required: true
          description: 申请ID
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReviewApplicationRequest'
      responses:
        '200':
          description: 审核成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: "保险申请审核成功"
                  data:
                    $ref: '#/components/schemas/InsuranceApplication'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'

  /insurance/applications-stats:
    get:
      summary: 获取参保申请统计
      description: 获取各状态的申请数量统计
      tags:
        - 参保申请
      security:
        - bearerAuth: []
      responses:
        '200':
          description: 获取成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: "获取保险申请统计成功"
                  data:
                    type: object
                    properties:
                      pending:
                        type: integer
                        description: 待初审数量
                        example: 10
                      initial_approved:
                        type: integer
                        description: 初审通过待复核数量
                        example: 5
                      under_review:
                        type: integer
                        description: 已支付待复核数量
                        example: 3
                      approved:
                        type: integer
                        description: 已支付数量
                        example: 20
                      rejected:
                        type: integer
                        description: 已拒绝数量
                        example: 2
                      paid:
                        type: integer
                        description: 已支付数量
                        example: 15
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'

  /insurance/categories:
    get:
      summary: 获取参保类型选项
      description: 获取可选的参保类型列表
      tags:
        - 参保申请
      security:
        - bearerAuth: []
      responses:
        '200':
          description: 获取成功
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: "获取参保类型选项成功"
                  data:
                    type: array
                    items:
                      type: string
                    example: ["牛", "羊", "猪", "鸡", "鸭", "鹅"]
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

  schemas:
    InsuranceApplication:
      type: object
      properties:
        id:
          type: integer
          description: 申请ID
          example: 1
        application_no:
          type: string
          description: 申请单号
          example: "20230814205416141"
        customer_name:
          type: string
          description: 投保人姓名
          example: "张三"
        customer_id_card:
          type: string
          description: 身份证号（脱敏显示）
          example: "420***********0091"
        customer_phone:
          type: string
          description: 电话（脱敏显示）
          example: "186****2563"
        customer_address:
          type: string
          description: 参保地址
          example: "哈哈哈哈哈哈"
        insurance_type_id:
          type: integer
          description: 保险类型ID
          example: 1
        insurance_category:
          type: string
          description: 参保类型
          example: "牛"
        application_quantity:
          type: integer
          description: 申请数量
          example: 50
        application_amount:
          type: number
          format: decimal
          description: 申请金额
          example: 10000.00
        status:
          type: string
          enum: [pending, initial_approved, under_review, approved, rejected, paid]
          description: 申请状态
          example: "pending"
        remarks:
          type: string
          description: 备注
          example: "无"
        application_date:
          type: string
          format: date-time
          description: 申请时间
          example: "2023-08-14T20:54:16.000Z"
        review_notes:
          type: string
          description: 审核备注
          example: null
        reviewer_id:
          type: integer
          description: 审核人ID
          example: null
        review_date:
          type: string
          format: date-time
          description: 审核时间
          example: null
        documents:
          type: array
          description: 相关文档
          items:
            type: string
          example: []
        created_at:
          type: string
          format: date-time
          description: 创建时间
          example: "2023-08-14T20:54:16.000Z"
        updated_at:
          type: string
          format: date-time
          description: 更新时间
          example: "2023-08-14T20:54:16.000Z"
        insurance_type:
          $ref: '#/components/schemas/InsuranceType'
        reviewer:
          $ref: '#/components/schemas/User'

    InsuranceType:
      type: object
      properties:
        id:
          type: integer
          description: 保险类型ID
          example: 1
        name:
          type: string
          description: 保险类型名称
          example: "保险清示产品"
        description:
          type: string
          description: 保险类型描述
          example: "保险产品描述"

    User:
      type: object
      properties:
        id:
          type: integer
          description: 用户ID
          example: 1
        real_name:
          type: string
          description: 真实姓名
          example: "李四"
        username:
          type: string
          description: 用户名
          example: "admin"

    CreateInsuranceApplicationRequest:
      type: object
      required:
        - customer_name
        - customer_id_card
        - customer_phone
        - customer_address
        - insurance_type_id
      properties:
        customer_name:
          type: string
          description: 投保人姓名
          example: "张三"
          minLength: 2
          maxLength: 100
        customer_id_card:
          type: string
          description: 身份证号
          example: "420106199001010091"
          pattern: '^[1-9]\d{5}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[0-9Xx]$'
        customer_phone:
          type: string
          description: 电话号码
          example: "18612345678"
          pattern: '^1[3-9]\d{9}$'
        customer_address:
          type: string
          description: 参保地址
          example: "北京市北京市北京市测试区"
          minLength: 5
          maxLength: 255
        insurance_type_id:
          type: integer
          description: 保险类型ID
          example: 1
        insurance_category:
          type: string
          description: 参保类型
          example: "牛"
          maxLength: 50
        application_quantity:
          type: integer
          description: 申请数量
          example: 50
          minimum: 1
        application_amount:
          type: number
          format: decimal
          description: 申请金额
          example: 10000.00
          minimum: 0
        remarks:
          type: string
          description: 备注
          example: "特殊说明"

    UpdateInsuranceApplicationRequest:
      type: object
      properties:
        customer_name:
          type: string
          description: 投保人姓名
          example: "张三"
          minLength: 2
          maxLength: 100
        customer_id_card:
          type: string
          description: 身份证号
          example: "420106199001010091"
          pattern: '^[1-9]\d{5}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[0-9Xx]$'
        customer_phone:
          type: string
          description: 电话号码
          example: "18612345678"
          pattern: '^1[3-9]\d{9}$'
        customer_address:
          type: string
          description: 参保地址
          example: "北京市北京市北京市测试区"
          minLength: 5
          maxLength: 255
        insurance_type_id:
          type: integer
          description: 保险类型ID
          example: 1
        insurance_category:
          type: string
          description: 参保类型
          example: "牛"
          maxLength: 50
        application_quantity:
          type: integer
          description: 申请数量
          example: 50
          minimum: 1
        application_amount:
          type: number
          format: decimal
          description: 申请金额
          example: 10000.00
          minimum: 0
        remarks:
          type: string
          description: 备注
          example: "特殊说明"

    ReviewApplicationRequest:
      type: object
      required:
        - status
      properties:
        status:
          type: string
          enum: [initial_approved, under_review, approved, rejected, paid]
          description: 审核后的状态
          example: "initial_approved"
        review_notes:
          type: string
          description: 审核备注
          example: "审核通过"

    Pagination:
      type: object
      properties:
        page:
          type: integer
          description: 当前页码
          example: 1
        limit:
          type: integer
          description: 每页数量
          example: 10
        total:
          type: integer
          description: 总记录数
          example: 100
        totalPages:
          type: integer
          description: 总页数
          example: 10

  responses:
    BadRequest:
      description: 请求参数错误
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              message:
                type: string
                example: "请求参数错误"

    Unauthorized:
      description: 未授权
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              message:
                type: string
                example: "未授权访问"

    Forbidden:
      description: 权限不足
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              message:
                type: string
                example: "权限不足"

    NotFound:
      description: 资源不存在
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              message:
                type: string
                example: "资源不存在"

    InternalServerError:
      description: 服务器内部错误
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              message:
                type: string
                example: "服务器内部错误"