from django.contrib.auth.models import User
from django.db import models
from django.utils.translation import gettext_lazy

from console.models import NameDescriptionModel


class NetworkMap(NameDescriptionModel):
    """ Class for holding JSON with network map data
        :user - field for storing user, with which map is associated
        :map_json - field for storing json data for the network map
        :col_nodes - JSON for storing collapsed nodes on user graph
    """
    user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True)
    map_json = models.JSONField(default=dict)
    col_nodes = models.JSONField(default=dict, help_text=gettext_lazy('JSON for storing collapsed nodes on user graph'))
    shared_map = models.BooleanField(default=False)  # Declaring if this map could be seen by all users

    class Meta:
        unique_together = [['name', 'user']]


class NetworkMapBackgroundImage(NameDescriptionModel):
    """ Model for storing all background images for networkmaps
        :network_map - pk of the map, that current background image is linked to
        :bounds - field for storing position data for background image
        :locked (currently unused) - field for storing flag if picture is locked
        :url - field for providing static path of image for frontend to load
        :visible (currently unused) - field for storing flag if picture is visible or not
    """
    network_map = models.ForeignKey(NetworkMap, on_delete=models.CASCADE)
    bounds = models.JSONField(default=dict)
    locked = models.BooleanField(default=False)
    url = models.ImageField(upload_to='networkmap/', verbose_name=gettext_lazy('Network map background image'))
    visible = models.BooleanField(default=True)

    class Meta:
        unique_together = (("name", "network_map"))
