# application/models.py
from django.db import models
from django.utils import timezone
from core.models import BaseTimeStampModel, User
from listing.models import Listing
from terms.models import Terms
from vendor.models import Vendor


class Application(BaseTimeStampModel):
    listing = models.ForeignKey(Listing, on_delete=models.CASCADE, null=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        db_table = 'application'


class ApplicationRequirement(BaseTimeStampModel):
    application = models.ForeignKey(Application, on_delete=models.CASCADE, related_name='requirements')
    term_type = models.ForeignKey(Terms, on_delete=models.CASCADE, null=True)
    requirement = models.CharField(max_length=500)
    
    class Meta:
        db_table = 'application_requirement'


class SelectedProvider(models.Model):
    vendor = models.ForeignKey(Vendor, on_delete=models.CASCADE, null=True, related_name='selections')
    application = models.ForeignKey(Application, on_delete=models.CASCADE, null=True, related_name='selected_providers')

    class Meta:
        db_table = 'selected_provider'