from django import forms
from django.core.validators import RegexValidator
from .models import *


class BaseOrderCreationForm(forms.ModelForm):
    type_of_room = forms.ChoiceField(choices=Order.TYPE_OF_ROOM_CHOICES, required=False, label="Тип квартиры",
                                     widget=forms.RadioSelect(attrs={"class": "inline-input"}))
    is_require_design = forms.ChoiceField(choices=Order.REQUIRED_DESIGN_CHOICES, label="Требуется дизайн проект",
                                          required=False, widget=forms.RadioSelect(attrs={"class": "inline-input"}))
    purchase_of_material = forms.ChoiceField(choices=Order.PURCHASE_OF_MATERIAL_CHOICES, widget=forms.RadioSelect,
                                             required=False, label="Закуп материала")
    type_of_executor = forms.ChoiceField(choices=Order.TYPE_OF_EXECUTOR_CHOICES, widget=forms.RadioSelect,
                                         required=False, label="Тип исполнителя")

    class Meta:
        model = Order
        fields = [
            'name', 'description', 'square',
            'type_of_renovation', 'type_of_house', 'type_of_room',
            'is_require_design', 'purchase_of_material', 'type_of_executor',
            'is_with_warranty', 'is_with_contract', 'is_with_trade', 'is_with_cleaning', 'is_with_garbage_removal',
            'date_start', 'date_end',
            'approximate_price', 'work_time', 'address_city', 'address_text',
        ]


class UnregisteredUserOrderCreationForm(BaseOrderCreationForm):
    phone = forms.CharField(max_length=12, required=True, label="Телефон", help_text="для обратной связи", validators=[
        RegexValidator(regex="^\\+7[0-9]{10}$"),
    ])
    email = forms.EmailField(required=True)

    class Meta:
        model = Order
        fields = BaseOrderCreationForm.Meta.fields + ['phone', 'email']
