from django.utils.translation import ugettext_lazy as _
from django.db import models
from core.models import WinoseBaseWithTrackingModel


class ReportTemplate(WinoseBaseWithTrackingModel):
    class Meta:
        verbose_name = _('template')
        verbose_name_plural = _('templates')

    overview_url = 'templates_list'
    create_url = 'template_create'
    update_url = 'template_update'
    detail_url = 'template_detail'

    # the template needs a name
    name = models.CharField(
        max_length=64,
        blank=False,
        null=False,
        unique=True,
        verbose_name=_('name')
    )

    # automated remark when the measurement arrived under a certain odour unit value
    lower_threshold = models.FloatField(
        null=False,
        default=32.0,
        verbose_name=_('below detection threshold')
    )

    # remark text for that
    lower_threshold_remark = models.TextField(
        null=False,
        blank=True,
        verbose_name=_('below threshold remark')
    )

    # automated remark about a late analysis (after sampling time)
    late_analysis_text = models.TextField(
        null=False,
        blank=True,
        verbose_name=_('late analysis remark')
    )

    late_analysis_threshold = models.IntegerField(
        default=30,
        null=False,
        blank=True,
        verbose_name=_('late analysis threshold')
    )

    # client provided the bag, not self manufactured (onuk wanted that...)
    # this is identified by using the client supplied field in the sample table
    client_bag_remark = models.TextField(
        null=False,
        blank=True,
        verbose_name=_('client provided bag')
    )

    # no team ite reported, use this one e.g. for insufficient sample volume
    insufficient_volume_remark = models.TextField(
        null=False,
        blank=True,
        verbose_name=_('insufficient volume')
    )

    generic_remarks = models.TextField(
        null=False,
        blank=True,
        verbose_name=_('general remarks')
    )

    # no standard compliant identifier
    not_standard_compliant_remark = models.TextField(
        null=False,
        blank=True,
        verbose_name=_('not standard compliant')
    )

    # header lab address
    header_text = models.TextField(
        blank=False,
        null=False,
        verbose_name=_('header text')
    )

    # optional header logo
    header_logo = models.ImageField(
        null=True,
        blank=True,
        upload_to='images',
        verbose_name=_('header logo')
    )

    def __str__(self):
        return self.name
