from flask_wtf import FlaskForm
from wtforms import StringField, DecimalField, IntegerField, TextAreaField, FileField, SubmitField
from wtforms.validators import DataRequired

from wtforms import PasswordField
from wtforms.validators import Email, Length


def get_products_by_seller(db, seller_id):
    return list(db.products.find({"seller_id": seller_id}))

def insert_product(db, data):
    return db.products.insert_one(data)

def get_available_products(db, seller_id):
    return list(db.products.find({"seller_id": seller_id, "stock": {"$gt": 0}}))

def get_sold_out_products(db, seller_id):
    return list(db.products.find({"seller_id": seller_id, "stock": 0}))

class ProductForm(FlaskForm):
    name = StringField("Product Name", validators=[DataRequired()])
    description = TextAreaField("Product Description")
    price = DecimalField("Price", validators=[DataRequired()])
    stock = IntegerField("Stock Quantity", validators=[DataRequired()])
    image = FileField("Product Image")  # Optional if you're adding images
    submit = SubmitField("Add Product")

