from django.db import models
from mainapp.models import (
    Satellite, 
    Polarization, 
    Modulation,
    Standard,
    get_default_polarization,
    get_default_modulation,
    get_default_standard
)

class LyngSat(models.Model):
    id_satellite = models.ForeignKey(Satellite, on_delete=models.PROTECT, related_name="lyngsat", verbose_name="Спутник", null=True)
    polarization = models.ForeignKey(
        Polarization, default=get_default_polarization, on_delete=models.SET_DEFAULT, related_name="lyngsat", null=True, blank=True, verbose_name="Поляризация"
    )
    modulation = models.ForeignKey(
        Modulation, default=get_default_modulation, on_delete=models.SET_DEFAULT, related_name="lyngsat", null=True, blank=True, verbose_name="Модуляция"    
    )
    standard = models.ForeignKey(
        Standard, default=get_default_standard, on_delete=models.SET_DEFAULT, related_name="lyngsat", null=True, blank=True, verbose_name="Стандарт"    
    )
    frequency = models.FloatField(default=0, null=True, blank=True, verbose_name="Частота, МГц")
    sym_velocity = models.FloatField(default=0, null=True, blank=True, verbose_name="Символьная скорость, БОД")
    last_update = models.DateTimeField(null=True, blank=True, verbose_name="Дата посленего обновления")
    channel_info = models.CharField(max_length=20, blank=True, null=True, verbose_name="Описание источника")
    fec = models.CharField(max_length=30, blank=True, null=True, verbose_name="Коэффициент коррекции ошибок")
    url = models.URLField(max_length = 200, blank=True, null=True, verbose_name="Ссылка на страницу")

    def __str__(self):
        return f"Ист {self.frequency}, {self.polarization}"
    
    class Meta:
        verbose_name = "Источник LyngSat"
        verbose_name_plural = "Источники LyngSat"


