from django import forms

import re
from sicurezza.views import getSecurityLevelAll
from configurazione.views import *

from .models import *

class formCausale(forms.Form):
  def __init__(self,*args,**kwargs):
    forms.Form.__init__(self,*args,**kwargs)

  def listatemplate(self):
    _listatemplate = list()
    _listatemplate.append((0,''))
    f = Template.objects.all().filter(enabled=True)
    for i in f:
      _listatemplate.append((i.id,i.nome))
    return _listatemplate

  def listaservizi(self):
    _listaservizi = []
    _listaservizi.append((0,''))
    s = Servizi.objects.all().filter(enabled=True)
    for i in s:
      _listaservizi.append((i.id,i.nome))
    return _listaservizi

  def update(self):
    self.fields['nome'] = forms.CharField(required=True)
    self.fields['enabled']  = forms.BooleanField(required=False)
    self.fields['valore'] = forms.IntegerField(required=False)

    self.fields['send_email_user'] = forms.BooleanField(required=False)
    self.fields['send_email_admin'] = forms.BooleanField(required=False)
    self.fields['send_email_account'] = forms.BooleanField(required=False)
    self.fields['send_email_other'] = forms.BooleanField(required=False)

    self.fields['from_email'] = forms.CharField(required=True)

    self.fields['to_account'] = forms.CharField(required=False)
    self.fields['to_admin'] = forms.CharField(required=False)
    self.fields['to_other'] = forms.CharField(required=False)

    self.fields['date_expire_contract'] = forms.BooleanField(required=False)
    self.fields['date_expire_registrar'] = forms.BooleanField(required=False)

    self.fields['check_registrar'] = forms.BooleanField(required=False)

    self.fields['sms'] = forms.BooleanField(required=False)

    self.fields['renew_request'] = forms.BooleanField(required=False)
    self.fields['renew_authorized'] = forms.BooleanField(required=False)

    self.fields['close_request'] = forms.BooleanField(required=False)

    self.fields['template'] = forms.ChoiceField(required=True,choices=self.listatemplate())
    self.fields['template_account'] = forms.ChoiceField(required=True,choices=self.listatemplate())
    self.fields['template_admin'] = forms.ChoiceField(required=True,choices=self.listatemplate())
    self.fields['template_other'] = forms.ChoiceField(required=True,choices=self.listatemplate())

    self.fields['domain_service'] = forms.ChoiceField(required=True,choices=self.listaservizi())
    self.fields['domain_service_active'] = forms.BooleanField(required=False)
    self.fields['domain_tobedeleted'] = forms.BooleanField(required=False)

    self.fields['ordine'] = forms.IntegerField(required=False)

    

  '''
  
  template = forms.IntegerField(db_column='template')
  #template_sms = forms.CharField(db_col

  domain_opened = forms.BooleanField(db_column='domain_opened')
  domain_closed = forms.BooleanField(db_column='domain_closed')
  domain_suspended = forms.BooleanField(db_column='domain_suspended')
  domain_enabled = forms.BooleanField(db_column='domain_enabled')
  domain_tobedeleted = forms.BooleanField(db_column='domain_tobedelete')
  transferring_in = forms.BooleanField(db_column='transferring_in')
  transferring_out = forms.BooleanField(db_column='transferring_out')
  transferred_in_complete = forms.BooleanField(db_column='transferred_in_complete')
  transferred_out_complete = forms.BooleanField(db_column='transferred_out_complete')

  mail_opened = forms.BooleanField(db_column='mail_opened')
  mail_closed = forms.BooleanField(db_column='mail_closed')
  mail_tobedeleted = forms.BooleanField(db_column='mail_tobedeleted')
  mail_password= forms.BooleanField(db_column='mail_password')
  mail_resend = forms.BooleanField(db_column='mail_resend')
  mail_test = forms.BooleanField(db_column='mail_test')
  payment_ok = forms.BooleanField(db_column='payment_ok')
  payment_ko = forms.BooleanField(db_column='payment_ko')
    template = models.ForeignKey("template.Template",db_column="template",on_delete=models.PROTECT)
  renew_code = forms.BooleandFiled(....
  '''

