class Product(db.Model):
    __tablename__ = 'products'

    id_ = db.Column(db.Integer, primary_key=True)
    description = db.Column(db.String(200), nullable=False)
    order_lines = db.relationship('OrderLine', backref='product', lazy=True)
    promotion = db.relationship('ProductPromotion',
                                backref='product',
                                lazy=True)

    def __init__(self, id_, description):
        self.id_ = id_
        self.description = description

    def __repr__(self):
        return f"Product({self.id_}, '{self.description}')"
class VendorCommissions(db.Model):
    __tablename__ = 'vendor_commissions'

    vendor_commissions_id = db.Column(db.Integer, primary_key=True)
    vendor_id = db.Column(db.Integer)
    date = db.Column(db.DATE, nullable=False)
    rate = db.Column(db.FLOAT, nullable=False)
    order = db.relationship('Order', backref='vendor_commission', lazy=True)

    def __init__(self, vendor_id, date, rate):
        self.vendor_id = vendor_id
        self.date = date
        self.rate = rate

    def __repr__(self):
        return f"VendorCommissions({self.vendor_id}, {self.date}, {self.rate})"
class ProductPromotion(db.Model):
    __tablename__ = 'product_promotion'

    id_ = db.Column(db.Integer, primary_key=True)
    product_id = db.Column(db.Integer, db.ForeignKey('products.id_'))
    date = db.Column(db.DATE, nullable=False)
    promotion_id = db.Column(db.Integer,
                             db.ForeignKey('promotion.id_'),
                             nullable=False)
    order_lines = db.relationship('OrderLine', backref='orderline', lazy=True)

    def __init__(self, product_id, date, promotion_id):
        self.product_id = product_id
        self.date = date
        self.promotion_id = promotion_id

    def __repr__(self):
        return f"ProductPromotion({self.product_id}, {self.date}, {self.promotion_id})"
class Order(db.Model):
    __tablename__ = 'orders'

    id_ = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.Date,
                           nullable=False,
                           default=datetime.utcnow().date())
    vendor_id = db.Column(db.Integer,
                          db.ForeignKey('vendor_commissions.vendor_id'),
                          nullable=False)
    customer_id = db.Column(
        db.Integer, nullable=False
    )  # Foreign key if a customer class is created in the future
    order_lines = db.relationship('OrderLine', backref='order', lazy=True)

    def __init__(self, id_, created_at, vendor_id, customer_id):
        self.id_ = id_
        self.created_at = created_at
        self.vendor_id = vendor_id
        self.customer_id = customer_id

    def __repr__(self):
        return f"Order('{self.id_}', '{self.created_at}', '{self.vendor_id}', '{self.customer_id}')"