from django.forms import ModelForm
from django import forms
from models import *

from form_utils.forms import BetterModelForm

class ExamFormForm(ModelForm):

    class Meta:
        model = ExamForm
        fields = ('name','introduction','start_year','payment_amount','type','enabled')

class ModalityCategoryForm(ModelForm):

    class Meta:
        model = ModalityCategory
        fields = ('title','subtitle','order','minimum_scans', 'upload_disabled')

class ModalityItemForm(ModelForm):

    class Meta:
        model = ModalityItem
        fields=  ('name','category','type','order','minimum','maximum')


class ApplicantDetailsForm(BetterModelForm):

    def __init__(self,*args,**kwargs):
        super(ApplicantDetailsForm,self).__init__(*args,**kwargs)
        self.fields['title'].required = True
        self.fields['first_name'].required = True
        self.fields['surname'].required = True
        self.fields['email_address'].required = True
        self.fields['contact_number'].required = True
        self.fields['dob'].required = True
        self.fields['job_title'].required = True
        self.fields['current_employer'].required = True
        self.fields['employment_start_date'].required = True
        self.fields['work_address_1'].required = True
        self.fields['work_town'].required = True
        self.fields['work_county'].required = True
        self.fields['work_postcode'].required = True
        self.fields['work_country'].required = True
        #self.fields['modality_1_scans'].required = True
        #self.fields['modality_2_scans'].required = True
        #self.fields['modality_3_scans'].required = True

    class Meta:
        model = ExamApplication
        fieldsets = [
            ('personal_details',{'fields': ['title','first_name','surname','email_address','contact_number','dob'],'legend':'Personal Details','description':'Applicants for the practical exam must be an ordinary member of the SVT.'}),
            ('employment',{'fields': ['job_title','current_employer','employment_start_date'],'legend':'Employment','description':'Applicants for the practical exam must be currently employed in the UK or ireland to perform vascular diagnostic investigations.'}),
            ('work_address',{'fields': ['work_address_1','work_address_2','work_town','work_county','work_postcode','work_country', 'other_sites_worked'],'legend':'Work Address',}),
            ('mailing_address',{'fields': ['mailing_address_1','mailing_address_2','mailing_town','mailing_county','mailing_postcode','mailing_country'],'legend':'Mailing Address'}),
            #('eligable_scans',{'fields': ['modality_1_scans','modality_2_scans','modality_3_scans'],'legend':'Eligable Scans','description':'Applicants must have carried out at least 25 scans from each of core modalities 1-3 in the 3 months prior to applying to sit the practical exam. <br/><br/><i>NB: Copies of the reports of the above scans and local protocols must be available to the examiners on the day of the practical assessment. The reports must demonstrate that the majority of the scans found pathology and were not "normal".</i>'}),
        ]


class AcademicDetailsForm(BetterModelForm):

    def __init__(self,*args,**kwargs):
        super(AcademicDetailsForm,self).__init__(*args,**kwargs)
        self.fields['university_name'].required = True
        self.fields['degree_title'].required = True
        self.fields['degree_class'].required = True
        self.fields['year_awarded'].required = True
        self.fields['degree_certificate'].required = True

    class Meta:
        model = ExamApplication
        fieldsets = [
            ('undergraduate_education',{'fields': ['university_name','degree_title','degree_class','year_awarded','degree_certificate'],'legend':'Undergraduate Education'}),
            ('postgraduate_education',{'fields': ['pg_university_name','pg_degree_title','pg_year_awarded'],'legend':'Postgraduate Education (if applicable)'}),
        ]


class NonDegreeEvidenceForm(BetterModelForm):

    def __init__(self,*args,**kwargs):
        super(NonDegreeEvidenceForm,self).__init__(*args,**kwargs)
        self.fields['non_degree_evidence'].required = True

    class Meta:
        model = ExamApplication
        fieldsets = [
            ('non_degree',{'fields': ['non_degree_applicant',],'legend':'Non Degree Applicants'}),
            ('non_degree_evidence',{'fields': ['non_degree_evidence',],'legend':'','classes':['non_degree_evidence']})
        ]


class TheoryForm(ModelForm):

    class Meta:
        model = ExamApplication
        fields = ('phi_y1','phi_y2','phi_y3','phi_y4','phi_y5','phi_y6','vt_y1','vt_y2','vt_y3','vt_y4','vt_y5','vt_y6')
        #,'cpd_y1','cpd_y2','cpd_y3','cpd_y4','cpd_y5','cpd_y6',)


class TheoryResultsLetterForm(ModelForm):

    class Meta:
        model = ExamApplication
        fields = ('exam_results_letter',)


class ExperienceForm(ModelForm):

    def __init__(self,*args,**kwargs):
        super(ExperienceForm,self).__init__(*args,**kwargs)
        self.fields['three_years_experience'].required = True

    class Meta:
        model = ExamApplication
        fields = ('three_years_experience',)

class ExaminerForm(BetterModelForm):

    class Meta:
        model = ExamApplication
        fields = ('examiner_title','examiner_first_name','examiner_surname','examiner_email','examiner_unable_reason')

class ReferenceForm(ModelForm):

    class Meta:
        model = ExamApplicationReference
        fields = ('name','address_1','address_2','town','county','country','postcode','email','telephone','job_role')

class ReferenceUploadForm(ModelForm):

    def __init__(self,*args,**kwargs):
        super(ReferenceUploadForm,self).__init__(*args,**kwargs)
        self.fields['reference_upload'].required = True

    class Meta:
        model = ExamApplication
        fields = ('reference_upload',)

class DeclarationForm(ModelForm):

    def __init__(self,*args,**kwargs):
        super(DeclarationForm,self).__init__(*args,**kwargs)
        for field in self.fields:
            self.fields[field].required = True
        if self.instance.exam.type == 're-validation':
            self.fields['duplex_scans_completed'].required = False
            self.fields['duplex_scans_completed'].widget = forms.HiddenInput()
            self.fields['vascular_scanning_experience'].required = False
            self.fields['vascular_scanning_experience'].widget = forms.HiddenInput()

    class Meta:
        model = ExamApplication
        fields = ('ordinary_member','currently_employed','six_month_employed','scans_completed','copy_degree_certificate','theory_exams_passed','exam_results_letters','duplex_scans_completed','vascular_scanning_experience','suitable_avs_assessor','referees_provided','understand_retake')
