from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

class Vehicle(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    license_plate = db.Column(db.String(10), nullable=False, unique=True)
    model = db.Column(db.String(50), nullable=False)
    repostajes = db.relationship('Repostaje', backref='vehicle', lazy=True)

    def __repr__(self):
        return f'<Vehicle {self.license_plate}>'

class Repostaje(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    vehicle_id = db.Column(db.Integer, db.ForeignKey('vehicle.id'), nullable=False)
    amount = db.Column(db.Float, nullable=False)
    date = db.Column(db.Date, nullable=False)
    kilometers = db.Column(db.Float, nullable=False)
    liters = db.Column(db.Float, nullable=False)
    total_amount = db.Column(db.Float, nullable=False)

    def __repr__(self):
        return f'<Repostaje {self.id}>'
