from typing import List

from sqlalchemy.orm import Session

from models import User, Product, Purchase


def create_user(session: Session, email: str) -> User:
    user = User(email=email)
    session.add(user)
    session.commit()
    return user


def create_product(session: Session, name: str, price: float) -> Product:
    product = Product(name=name, price=price)
    session.add(product)
    session.commit()
    return product


def create_purchase(session: Session, user: User, product: Product, count: int) -> Purchase:
    purchase = Purchase(user=user, product=product, count=count)
    session.add(purchase)
    session.commit()
    return purchase


def get_user_purchases(user: User) -> List[Purchase]:
    return user.purchases
