from django import forms
from .models import HelpdeskSubmission

class HelpdeskSubmissionForm(forms.ModelForm):
    class Meta:
        model = HelpdeskSubmission
        fields = ['title', 'description', 'image', 'status']  # Include 'status' field
        widgets = {
            'status': forms.HiddenInput()  # Hide status field in the form
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['status'].initial = 1  # Set default value for status

    def save(self, commit=True, user=None):
        # Ensure the user is passed in and set when saving the form
        submission = super().save(commit=False)
        if user:
            submission.user = user
        if commit:
            submission.save()
        return submission