from django import forms
from django.db import models
from django.utils import timezone

from parc_info.models import Services as Services

SITE = [
	('GENT', 'Gentilly'),
	('CAP', 'Ambroise Paré'),
	('HPN', 'Hopital Privé de Nancy Loraine'),
	('EXT', 'Extérieur'),
]

login_type = (
	(u'pnom', u'1er lettre du Prenom puis Nom'),
	(u'pnomMGAG', u'1er lettre du Prenom puis Nom en Mag'),
	(u'pre.nom', u'Prenom.Nom'),
	(u'preMAG.nomMAG', u'PRENOM.NOM'),
	(u'mixed', u'Au choix'),
	(u'pre.nom', u'Lié a AD'),
	(u'pre.nom@el', u'Lié au compte email'),
	(u'autre', u'Autre'),
)

class GES_APP(models.Model):
	GESAP_Nom = models.CharField("Nom", max_length=16)
	GESAP_ltype = models.CharField("Type de Login",choices=login_type, max_length=48, default='pre.nom')
	GESAP_Sup_Nom = models.CharField("Champ complaimentaire", max_length=16, blank=True)
	GESAP_Commentaire = models.TextField("Aide pour la création du compte", blank=True)

	def __str__(self):
		return self.GESAP_Nom

	class Meta:
		verbose_name = "Les apllications métiers"
		verbose_name_plural = "Les apllications métiers"
		ordering = ['GESAP_Nom']

class GES_Fonction(models.Model):
	GESFC_Nom = models.CharField("Nom", max_length=16)
	
	def __str__(self):
		return self.GESFC_Nom

	class Meta:
		verbose_name = "Les fonctions"
		verbose_name_plural = "Les fonctions"
		ordering = ['GESFC_Nom']
		
class GES_User(models.Model):
	GES_L_Site = models.CharField("Site", max_length=4, choices=SITE, default='HPN')
	GES_Nom = models.CharField("Nom", max_length=16)
	GES_Prenom = models.CharField("Prénom", max_length=16)
	GES_Motdepasse = models.CharField("Mot de passe", max_length=16)
	GES_Service = models.ForeignKey(Services, on_delete=models.CASCADE)
	GES_Fonction = models.ForeignKey(GES_Fonction, on_delete=models.CASCADE, blank=True, null=True)
	GES_APPs = models.ManyToManyField(GES_APP)
	GES_OK = models.BooleanField("Création complété", default = False)
	ordering = ['GES_Service']

	GES_Commentaire = models.TextField("Commentaires", blank=True, null=True)

	def __str__(self):
		return self.GES_Nom + ' ' + self.GES_Prenom

	class Meta:
		verbose_name = "Les utilisateurs"
		verbose_name_plural = "Les utilisateurs"

class GES_APPLink(models.Model):
	GES_APPLink_User = models.ForeignKey(GES_User, on_delete=models.CASCADE)
	GES_APPLink_APP = models.ForeignKey(GES_APP, on_delete=models.CASCADE)
	GES_APPLink_Login = models.CharField("Login", max_length=48)
	GES_APPLink_MDP = models.CharField("Mot de passe", max_length=16)
	GES_APPLink_Sup = models.CharField("Info supplaimentaire", max_length=16, blank=True)
	GES_APPLink_Create = models.BooleanField("Crée", default = False)
	
class GES_User_form(forms.ModelForm):
	class Meta:
		model = GES_User
		fields = '__all__'

class GES_APPLink_form(forms.ModelForm):
	class Meta:
		model = GES_APPLink
		fields = ['GES_APPLink_Login', 'GES_APPLink_MDP', 'GES_APPLink_Sup']

class PSearch_form(forms.Form):
	PSearch = forms.CharField(label='Recherche', max_length=128)