from django.db import models

from apps.core.models import TimeStampedModel, Visibility


class ReportType(models.TextChoices):
    PROGRESS = "progress", "Construction progress"
    FINANCIAL = "financial", "Financial"
    INVESTMENT = "investment", "Investment"
    ANNUAL = "annual", "Annual"
    PUBLIC = "public", "Public"


class Report(TimeStampedModel):
    project = models.ForeignKey("projects.Project", on_delete=models.CASCADE, related_name="reports")
    title = models.CharField(max_length=180)
    report_type = models.CharField(max_length=20, choices=ReportType.choices, default=ReportType.PROGRESS)
    period_label = models.CharField(max_length=80, blank=True)
    summary = models.TextField(blank=True)
    visibility = models.CharField(max_length=16, choices=Visibility.choices, default=Visibility.INVESTOR)
    document = models.ForeignKey(
        "documents.Document",
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name="reports",
    )
    published_on = models.DateField(null=True, blank=True)

    class Meta:
        ordering = ["-published_on", "-id"]

    def __str__(self):
        return self.title
