from django.db import models
from common.models import LinesModel, ContainerTypeModel

# Create your models here.
class Container(models.Model):
    number = models.CharField(max_length=11)
    line = models.ForeignKey(
        LinesModel,
        on_delete=models.CASCADE,
        related_name='container_lines',
    )
    container_type = models.ForeignKey(
        ContainerTypeModel,
        on_delete=models.CASCADE,
        related_name='container_container_types',
    )
    received_on = models.DateTimeField(auto_now_add=True)
    received_by = models.ForeignKey(
        'accounts.DepotUser',
        on_delete=models.CASCADE,
        related_name='container_received_by',
    )
    receive_vehicle = models.CharField(max_length=100, blank=True, null=True)
    damages = models.TextField(blank=True, null=True)
    heavy_damaged = models.BooleanField(default=False)
    position = models.CharField(max_length=100, blank=True, null=True)
    swept = models.BooleanField(default=False)
    swept_on = models.DateTimeField(blank=True, null=True)
    swept_by = models.ForeignKey(
        'accounts.DepotUser',
        on_delete=models.CASCADE,
        related_name='container_swept_by',
        blank=True,
        null=True
    )
    washed = models.BooleanField(default=False)
    washed_on = models.DateTimeField(blank=True, null=True)
    washed_by = models.ForeignKey(
        'accounts.DepotUser',
        on_delete=models.CASCADE,
        related_name='container_washed_by',
        blank=True,
        null=True
    )
    booking = models.ForeignKey(
        'booking.Booking',
        on_delete=models.CASCADE,
        related_name='container_bookings',
        blank = True,
        null = True
    )
    expedited = models.BooleanField(default=False)
    expedited_on = models.DateTimeField(blank=True, null=True)
    expedited_by = models.ForeignKey(
        'accounts.DepotUser',
        on_delete=models.CASCADE,
        related_name='container_expedited_by',
        blank=True,
        null=True
    )
    expedition_vehicle = models.CharField(max_length=100, blank=True, null=True)


class ContainerHistory(Container):
    operation = models.ForeignKey(
        'common.OperationModel',
        on_delete=models.CASCADE,
        related_name='history_operations',
    )
    operation_date = models.DateTimeField(auto_now_add=True)
    container = models.ForeignKey(
        Container,
        on_delete=models.CASCADE,
        related_name='history_containers'
    )
