from django.db import models
from django.core.files.storage import FileSystemStorage
from django.contrib.auth.models import User


class Paragraph(models.Model):
    date = models.DateField(blank=False, null=False, unique=False)
    link = models.CharField(max_length=255, unique=False)
    paragraph = models.TextField(blank=False, null=False)


    class Meta:
        verbose_name_plural = "Paragraphs"
        ordering = ['-date']

    def __unicode__(self):
        return "%s" % self.date

    def __str__(self):
        return u'%s' % self.date


class OriginalContract(models.Model):
    number = models.CharField(max_length=63, unique=False)
    para = models.ForeignKey(Paragraph, on_delete=models.CASCADE)

    def __unicode__(self):
        return "%s" % self.number

    def __str__(self):
        return u'%s' % self.number


class Tags(models.Model):
    name = models.CharField(max_length=31, unique=True)
    desc = models.TextField(blank=True, null=True)

    def __unicode__(self):
        return "%s" % self.name

    def __str__(self):
        return u'%s' % self.name



class Company(models.Model):
    name = models.CharField(max_length=63)
    unq_entity_id = models.CharField(max_length=63, blank=False, null=False, unique=True)
    website = models.URLField(max_length=127, blank=True, null=True)
    short_desc = models.CharField(max_length=63, blank=True, null=True)
    long_desc = models.TextField(blank=True, null=True)
    gmap_link = models.CharField(max_length=253, blank=True, null=True)
    tags = models.ManyToManyField(Tags, blank=True)

    address_complete = models.CharField(max_length=127, blank=True, null=True)
    address_numbers = models.CharField(max_length=63, blank=True, null=True)
    address_type = models.CharField(max_length=31, blank=True, null=True)
    city = models.CharField(max_length=127, blank=True, null=True)
    state = models.CharField(max_length=127, blank=True, null=True)
    zip_code = models.CharField(max_length=15, blank=True, null=True)


    class Meta:
        unique_together = ("name", "website")
        verbose_name_plural = "Companies"
        ordering = ['name']

    def __unicode__(self):
        return "%s" % self.name

    def __str__(self):
        return u'%s' % self.name


class Exec(models.Model):
    name = models.CharField(max_length=63)
    company = models.ForeignKey(Company, on_delete=models.CASCADE)
    linkedin = models.URLField(max_length=127, blank=True, null=True)
    short_desc = models.CharField(max_length=63, blank=True, null=True)
    tags = models.ManyToManyField(Tags, blank=True)


    class Meta:
        unique_together = ("name", "company")
        verbose_name_plural = "Execs"
        ordering = ['name']

    def __unicode__(self):
        return "%s" % self.name

    def __str__(self):
        return u'%s' % self.name


class Contract(models.Model):        
    title = models.CharField(max_length=254, unique=False)
    original_contract_number = models.ForeignKey(OriginalContract, on_delete=models.CASCADE, blank=True, null=True)
    company = models.ForeignKey(Company, blank=True, null=True, on_delete=models.CASCADE)
    notice_id = models.CharField(max_length=31, blank=False, null=False)
    related_notice_id = models.CharField(max_length=31, blank=True, null=True)
    opp_type = models.CharField(max_length=63, blank=True, null=True)
    pub_date = models.DateTimeField(blank=True, null=True)
    pub_date_txt = models.CharField(max_length=63, blank=True, null=True)
    us_dept = models.CharField(max_length=31, blank=True, null=True)
    us_dept_sub_tier = models.CharField(max_length=31, blank=True, null=True)
    major_dept = models.CharField(max_length=31, blank=True, null=True)
    us_office = models.CharField(max_length=31, blank=True, null=True)
    award_date = models.DateField(blank=True, null=True)
    award_num = models.CharField(max_length=31, blank=True, null=True)
    unq_entity_id = models.CharField(max_length=31, blank=True, null=True)
    contract_value = models.CharField(max_length=31, blank=True, null=True)
    contract_value_int = models.FloatField(blank=True, null=True)
    orig_set_aside = models.CharField(max_length=127, blank=True, null=True)
    prod_svc_code = models.CharField(max_length=127, blank=True, null=True)
    naics_code = models.CharField(max_length=127, blank=True, null=True)
    contract_url = models.CharField(max_length=127, blank=True, null=True)
    description = models.TextField(blank=True, null=True)


    class Meta:
        # unique_together = ("notice_id", "unq_entity_id", "pub_date_txt")
        verbose_name_plural = "Contracts"
        ordering = ['-pub_date', 'notice_id']

    def __unicode__(self):
        return "%s" % self.notice_id

    def __str__(self):
        return u'%s' % self.notice_id