# User/model.py

from config import Config
from pymongo import MongoClient

client = MongoClient(Config.MONGO_URI)
db = client['fyp']

def get_filtered_products(query, sort_by=None, page=1, per_page=6):
    collection = db['preprocessData']
    cursor = collection.find(query)
    if sort_by:
        cursor = cursor.sort([sort_by])
    total = cursor.count()
    results = list(cursor.skip((page - 1) * per_page).limit(per_page))
    return results, total
