"""
Journey forms for CRUD operations
"""
from django import forms
from django.utils.translation import gettext_lazy as _

from .models import (
    PatientJourneyStageTemplate,
    PatientJourneyTemplate,
)


class PatientJourneyTemplateForm(forms.ModelForm):
    """Form for creating/editing journey templates"""
    
    class Meta:
        model = PatientJourneyTemplate
        fields = [
            'name', 'name_ar', 'hospital', 'journey_type',
            'description', 'is_active',
            'send_post_discharge_survey', 'post_discharge_survey_delay_hours'
        ]
        widgets = {
            'name': forms.TextInput(attrs={
                'class': 'form-control',
                'placeholder': 'e.g., Inpatient Journey'
            }),
            'name_ar': forms.TextInput(attrs={
                'class': 'form-control',
                'placeholder': 'الاسم بالعربية'
            }),
            'hospital': forms.Select(attrs={'class': 'form-select'}),
            'journey_type': forms.Select(attrs={'class': 'form-select'}),
            'description': forms.Textarea(attrs={
                'class': 'form-control',
                'rows': 3,
                'placeholder': 'Describe this journey...'
            }),
            'is_active': forms.CheckboxInput(attrs={'class': 'form-check-input'}),
            'send_post_discharge_survey': forms.CheckboxInput(attrs={'class': 'form-check-input'}),
            'post_discharge_survey_delay_hours': forms.NumberInput(attrs={
                'class': 'form-control',
                'min': '0'
            }),
        }


class PatientJourneyStageTemplateForm(forms.ModelForm):
    """Form for creating/editing journey stage templates"""
    
    class Meta:
        model = PatientJourneyStageTemplate
        fields = [
            'name', 'name_ar', 'code', 'order',
            'trigger_event_code', 'survey_template', 'is_optional', 'is_active'
        ]
        widgets = {
            'name': forms.TextInput(attrs={
                'class': 'form-control',
                'placeholder': 'e.g., Admission'
            }),
            'name_ar': forms.TextInput(attrs={
                'class': 'form-control',
                'placeholder': 'الاسم بالعربية'
            }),
            'code': forms.TextInput(attrs={
                'class': 'form-control',
                'placeholder': 'e.g., ADMISSION'
            }),
            'order': forms.NumberInput(attrs={
                'class': 'form-control',
                'min': '0'
            }),
            'trigger_event_code': forms.TextInput(attrs={
                'class': 'form-control',
                'placeholder': 'e.g., OPD_VISIT_COMPLETED'
            }),
            'survey_template': forms.Select(attrs={'class': 'form-select form-select-sm'}),
            'is_optional': forms.CheckboxInput(attrs={'class': 'form-check-input'}),
            'is_active': forms.CheckboxInput(attrs={'class': 'form-check-input'}),
        }


PatientJourneyStageTemplateFormSet = forms.inlineformset_factory(
    PatientJourneyTemplate,
    PatientJourneyStageTemplate,
    form=PatientJourneyStageTemplateForm,
    extra=1,
    can_delete=True,
    min_num=1,
    validate_min=True
)
