#-*- coding:utf-8 -*-

from django.forms import CharField, ChoiceField, Form, ModelChoiceField

from semantics.models import GeneralSelectivePreference, SelectivePreferenceRelations, SemanticRole

class RoleForm(Form):
    negation = ChoiceField(choices=[('', u'---'), ('!', u'!')], required=False,
                                    label=u'')
    role = ModelChoiceField(label=u'Rola', required=False,
                            queryset=SemanticRole.objects.filter(gradient__isnull=True))
    attribute = ModelChoiceField(label=u'Atrybut', required=False,
                               queryset=SemanticRole.objects.filter(gradient__isnull=False))
    preference_type = ChoiceField(choices=[('general', u'Predefiniowana'), ('synset', u'Słowosieć'), ('relation', u'Relacja')], 
                                  label=u'Preferencje selekcyjne', required=False)
    preferences = []
  
    def __init__(self, negation=None, sel_role=None, sel_attribute=None,
                  sel_preferences=[], 
                  *args, **kwargs):
        super(RoleForm, self).__init__(*args, **kwargs)
        self.fields['negation'].initial = negation
        self.fields['role'].initial = sel_role
        self.fields['attribute'].initial = sel_attribute
        self.preferences = sel_preferences
        
class GeneralSelPrefForm(Form):
    general_pref = ModelChoiceField(label=u'Predefiniowana', 
                                    queryset=GeneralSelectivePreference.objects.order_by('name'), required=False)
    
    def pref_type(self):
        return 'general'
  
    def __init__(self, sel_preference=None, *args, **kwargs):
        super(GeneralSelPrefForm, self).__init__(*args, **kwargs)
        self.fields['general_pref'].initial = sel_preference

class SynsetSelPrefForm(Form):
    synset_pref = CharField(label=u'Słowosieć', required=False)
    
    def pref_type(self):
        return 'synset'
  
    def __init__(self, sel_preference=None, *args, **kwargs):
        super(SynsetSelPrefForm, self).__init__(*args, **kwargs)
        self.fields['synset_pref'].initial = sel_preference
        
class RelationalSelPrefForm(Form):
    relational_pref_relation = ModelChoiceField(label=u'Relacja', 
                                queryset=SelectivePreferenceRelations.objects.all(), required=False)
    relational_pref_role = ModelChoiceField(label=u'Rola', required=False,
                            queryset=SemanticRole.objects.filter(gradient__isnull=True))
    relational_pref_attribute = ModelChoiceField(label=u'Atrybut', required=False,
                               queryset=SemanticRole.objects.filter(gradient__isnull=False))
  
    def pref_type(self):
        return 'relational'
        
    def __init__(self, sel_relation=None, sel_role=None, sel_attribute=None, *args, **kwargs):
        super(RelationalSelPrefForm, self).__init__(*args, **kwargs)
        self.fields['relational_pref_relation'].initial = sel_relation
        self.fields['relational_pref_role'].initial = sel_role
        self.fields['relational_pref_attribute'].initial = sel_attribute
    