from typing import Required
from django.db import models

from api.models import User

# Create your models here.
class Vehicle(models.Model):
    vehicle_number = models.CharField(max_length=15, unique=True)
    trailer1_number = models.CharField(max_length=15, null=True, blank=True)
    trailer2_number = models.CharField(max_length=15, null=True, blank=True)
    driver_pid = models.CharField(max_length=50, null=True, blank=True)
    
    tare = models.IntegerField(null=True, blank=True)
    tare_date = models.DateTimeField(null=True, blank=True)
    tare_user = models.ForeignKey(User, null=True, blank=True, related_name='user_vehicle_tare', on_delete=models.SET_NULL)
    tare_manual = models.BooleanField(default=False)

    gross = models.IntegerField(null=True, blank=True)
    gross_date = models.DateTimeField(null=True, blank=True)
    gross_user = models.ForeignKey(User, null=True, blank=True, related_name='user_vehicle_gross', on_delete=models.SET_NULL)
    gross_manual = models.BooleanField(default=False)

    net = models.IntegerField(null=True, blank=True)
    net_date = models.DateTimeField(null=True, blank=True)
    net_user = models.ForeignKey(User, null=True, blank=True, related_name='user_vehicle_net', on_delete=models.SET_NULL)

    doc_number = models.CharField(max_length=20, null=True, blank=True, unique=True)



    def __str__(self):
        return f"{self.vehicle_number}"
    
class VehicleExtra(models.Model):
    vehicle = models.OneToOneField(
        Vehicle, on_delete=models.CASCADE, related_name="extra"
    )
    data = models.JSONField(default=dict)