from django import forms

from module_iam.models import IAmPrincipal
from module_project import constants

from .models import FoodIngredintDataset, ChronicCondition, Intolerance, PastTreatment, Symptoms


class FoodIngredintDatasetForm(forms.ModelForm):
    class Meta:
        model = FoodIngredintDataset
        fields = ['food_name', 'ingredients']

class UploadFileForm(forms.Form):
    file = forms.FileField()

class IntoleranceForm(forms.ModelForm):
    class Meta:
        model = Intolerance
        fields = ['name', 'duration']
        label = {
            "name": "intolerance",
            "duration": "For how long have you been experiencing this intolerance"
        }

    def save(self, principal_id, commit=True):
        instance = super().save(commit=False)
        instance.principal = IAmPrincipal.objects.get(pk=principal_id)
        if commit:
            instance.save()
        return instance


class SymptomsForm(forms.ModelForm):
    class Meta:
        model = Symptoms
        fields = ['name', 'duration']
        label = {
            "name": "Symptoms",
            "duration": "For how long have you been experiencing this intolerance"
        }

    def save(self, principal_id, commit=True):
        instance = super().save(commit=False)
        instance.principal = IAmPrincipal.objects.get(pk=principal_id)
        if commit:
            instance.save()
        return instance

class SymptomsForm(forms.ModelForm):
    class Meta:
        model = Symptoms
        fields = ['name', 'duration']
        label = {
            "name": "Symptoms",
            "duration": "For how long have you been experiencing this intolerance"
        }

    def save(self, principal_id, commit=True):
        instance = super().save(commit=False)
        instance.principal = IAmPrincipal.objects.get(pk=principal_id)
        if commit:
            instance.save()
        return instance


class PastTreatmentForm(forms.ModelForm):
    class Meta:
        model = PastTreatment
        fields = ['name', 'duration']
        label = {
            "name": "PastTreatment",
            "duration": "Treatment Date"
        }

    def save(self, principal_id, commit=True):
        instance = super().save(commit=False)
        instance.principal = IAmPrincipal.objects.get(pk=principal_id)
        if commit:
            instance.save()
        return instance


class ChronicConditionForm(forms.ModelForm):
    class Meta:
        model = ChronicCondition
        fields = ['name', 'duration']
        label = {
            "name": "Chronic Condition",
            "duration": "For how long have you been experiencing this disease"
        }

    def save(self, principal_id, commit=True):
        instance = super().save(commit=False)
        instance.principal = IAmPrincipal.objects.get(pk=principal_id)
        if commit:
            instance.save()
        return instance