# nimbus/models.py
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _


class Buildmatrix(models.Model):

    owner = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        null=True,
        related_name='Owned_matrix',
    )
    
    build = models.ForeignKey(
        'Nimbussetting',
        related_name='matrix_build', 
        verbose_name=_('Build'),
    )

    CATEGORY_CHOICES = (
        ('MLB', _('MLB')),
        ('FATP', _('FATP')),
    )
    category = models.CharField(
        max_length=5, 
        choices=CATEGORY_CHOICES,
        verbose_name=_('Category'),
        help_text=_(
            "必填項目*"
        ),
    )

    url = models.URLField(
        max_length=200,
        blank=False,
        null=False,
        verbose_name=_("Build Matrix's URL"),
    )

    last_version = models.CharField(
        max_length=10,
        blank=True,
        null=True,
        verbose_name=_('Last Version'),
    )

    created_at = models.DateTimeField(
        auto_now_add=True,
        editable=False,
    )

    class Meta:
        verbose_name = _('Build Matrix')
        verbose_name_plural = _('Build Matrixs')

    def __str__(self):
        return str(self.build) + ', ' + self.last_version


class Nimbussetting(models.Model):

    product = models.CharField(
        max_length=10,
        blank=True, null=True,
    )

    build = models.CharField(
        max_length=10,
        blank=True, null=True,
    )

    account = models.CharField(
        max_length=20,
        blank=True, null=True,
        verbose_name=_('Nimbus account'),
    )

    password = models.CharField(
        max_length=20,
        blank=True, null=True,
        verbose_name=_('Nimbus password'),
    )

    created_at = models.DateTimeField(
        auto_now_add=True,
        editable=False,
    )

    class Meta:
        ordering = ['-created_at']
        verbose_name = _('Nimbus Setting')
        verbose_name_plural = _('Nimbus Settings')

    def __str__(self):
        return self.product + ', ' + self.build


