# models.py -  vSGW Models

from core.models import Service, TenantWithContainer, Image
from django.db import models, transaction

MCORD_KIND = 'EPC'

SERVICE_NAME = 'vsgw'
SERVICE_NAME_VERBOSE = 'Virtual SGW Service'
SERVICE_NAME_VERBOSE_PLURAL = 'Virtual SGW Services'
TENANT_NAME_VERBOSE = 'Virtual SGW Tenant'
TENANT_NAME_VERBOSE_PLURAL = 'Virtual SGW Tenants'

class VSGWService(Service):

    KIND = SERVICE_NAME

    class Meta:
        proxy = True
        app_label = SERVICE_NAME
        verbose_name = SERVICE_NAME_VERBOSE

class VSGWTenant(TenantWithContainer):

    KIND = SERVICE_NAME

    class Meta:
        verbose_name = TENANT_NAME_VERBOSE

    tenant_message = models.CharField(max_length=254, help_text="Tenant Message to Display")
    image_name = models.CharField(max_length=254, help_text="Name of VM image")

    def __init__(self, *args, **kwargs):
        vsgw_service = VSGWService.get_service_objects().all()
        if vsgw_service:
            self._meta.get_field('provider_service').default = vsgw_service[0].id
        super(VSGWTenant, self).__init__(*args, **kwargs)

    def save(self, *args, **kwargs):
        super(VSGWTenant, self).save(*args, **kwargs)
        model_policy_vsgwtenant(self.pk)

    def delete(self, *args, **kwargs):
        self.cleanup_container()
        super(VSGWTenant, self).delete(*args, **kwargs)

    @property
    def image(self):
        img = self.image_name.strip()
        if img.lower() != "default":
            return Image.objects.get(name=img)
        else: 
            return super(VSGWTenant, self).image

def model_policy_vsgwtenant(pk):
    with transaction.atomic():
        tenant = VSGWTenant.objects.select_for_update().filter(pk=pk)
        if not tenant:
            return
        tenant = tenant[0]
        tenant.manage_container()
