protectApiRoute = (req, res, next) => {
  const token = req.cookies.jwt || req.headers.authorization?.split(' ')[1];
  
  if (!token) {
    return res.status(401).json({ message: 'Authentication required' });
  }

  try {
    const decoded = jwt.verify(token, JWT_SECRET);
    req.user = decoded;
    next();
  } catch (error) {
    return res.status(403).json({ message: 'Invalid or expired token' });
  }
}
@swagger
components:
  schemas:
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: Error resetting documents
    User:
      type: object
      required:
        - username
        - password
      properties:
        username:
          type: string
          description: User's username
        password:
          type: string
          format: password
          description: User's password (will be hashed)
    Document:
      type: object
      properties:
        id:
          type: integer
          description: Document ID
          example: 123
        title:
          type: string
          description: Document title
          example: Invoice #12345
        tags:
          type: array
          items:
            type: integer
          description: Array of tag IDs
          example: [1, 4, 7]
        correspondent:
          type: integer
          description: Correspondent ID
          example: 5
    HistoryItem:
      type: object
      properties:
        document_id:
          type: integer
          description: Document ID
          example: 123
        title:
          type: string
          description: Document title
          example: Invoice #12345
        created_at:
          type: string
          format: date-time
          description: Date and time when the processing occurred
        tags:
          type: array
          items:
            $ref: '#/components/schemas/Tag'
        correspondent:
          type: string
          description: Document correspondent name
          example: Acme Corp
        link:
          type: string
          description: Link to the document in Paperless-ngx
    Tag:
      type: object
      properties:
        id:
          type: integer
          description: Tag ID
          example: 5
        name:
          type: string
          description: Tag name
          example: Invoice
        color:
          type: string
          description: Tag color (hex code)
          example: "#FF5733"