from django import forms
from .models import Report, CustomerTemplateMapping, ProductDrawing


from core.utils import SHEET_NAMES

class ReportForm(forms.ModelForm):
    class Meta:
        model = Report
        fields = ['name', 'created_by', 'file']  # Include the fields you want in the form

class CustomerTemplateMappingForm(forms.ModelForm):
    template_names = forms.MultipleChoiceField(
        choices=[(key, label) for key, label in SHEET_NAMES.items()],
        widget=forms.CheckboxSelectMultiple,
        required=False,
        label="Templates"
    )

    class Meta:
        model = CustomerTemplateMapping
        fields = ['customer_name', 'export_template', 'template_names']

    def clean_template_names(self):
        # convert data to list of selected template keys
        return self.cleaned_data['template_names']

class ProductDrawingForm(forms.ModelForm):
    class Meta:
        model = ProductDrawing
        fields = ['code_no', 'code_no_mks',  'lot_no', 'drawing', 'description']
