from django.db import models
from django.core.validators import MaxValueValidator


class Vehiculo(models.Model):
    marca = models.CharField(max_length=200)
    modelo = models.CharField(max_length=200)
    matricula = models.CharField(max_length=200)
    foto = models.ImageField(upload_to='vehiculos/', blank=True, null=True)  # Nuevo campo

    def __str__(self):
        return self.marca


class Repostaje(models.Model):
    vehiculo = models.ForeignKey(Vehiculo, on_delete=models.CASCADE)
    fecha = models.DateField()
    kms = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    litros = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
    descuento = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
    importe = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
    precioxlitro = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
    kmsrecorridos = models.DecimalField(max_digits=10, decimal_places=0, blank=True, null=True)
    consumo = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)

    def __str__(self):
        return str(self.fecha)
