"""
AI Engine forms
"""
from django import forms

from .models import SentimentResult


class AnalyzeTextForm(forms.Form):
    """Form for analyzing text"""
    
    text = forms.CharField(
        widget=forms.Textarea(attrs={
            'class': 'form-control',
            'rows': 6,
            'placeholder': 'Enter text to analyze...'
        }),
        label='Text',
        help_text='Enter the text you want to analyze for sentiment'
    )
    
    language = forms.ChoiceField(
        choices=[
            ('', 'Auto-detect'),
            ('en', 'English'),
            ('ar', 'Arabic'),
        ],
        required=False,
        widget=forms.Select(attrs={'class': 'form-select'}),
        label='Language',
        help_text='Select language or leave blank for auto-detection'
    )
    
    extract_keywords = forms.BooleanField(
        required=False,
        initial=True,
        widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}),
        label='Extract Keywords'
    )
    
    extract_entities = forms.BooleanField(
        required=False,
        initial=True,
        widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}),
        label='Extract Entities'
    )
    
    detect_emotions = forms.BooleanField(
        required=False,
        initial=True,
        widget=forms.CheckboxInput(attrs={'class': 'form-check-input'}),
        label='Detect Emotions'
    )


class SentimentFilterForm(forms.Form):
    """Form for filtering sentiment results"""
    
    sentiment = forms.ChoiceField(
        choices=[
            ('', 'All Sentiments'),
            ('positive', 'Positive'),
            ('neutral', 'Neutral'),
            ('negative', 'Negative'),
        ],
        required=False,
        widget=forms.Select(attrs={'class': 'form-select'}),
        label='Sentiment'
    )
    
    language = forms.ChoiceField(
        choices=[
            ('', 'All Languages'),
            ('en', 'English'),
            ('ar', 'Arabic'),
        ],
        required=False,
        widget=forms.Select(attrs={'class': 'form-select'}),
        label='Language'
    )
    
    ai_service = forms.ChoiceField(
        choices=[
            ('', 'All Services'),
            ('stub', 'Stub'),
            ('openai', 'OpenAI'),
            ('azure', 'Azure'),
            ('aws', 'AWS'),
        ],
        required=False,
        widget=forms.Select(attrs={'class': 'form-select'}),
        label='AI Service'
    )
    
    min_confidence = forms.DecimalField(
        required=False,
        min_value=0,
        max_value=1,
        decimal_places=2,
        widget=forms.NumberInput(attrs={
            'class': 'form-control',
            'step': '0.1',
            'placeholder': '0.0'
        }),
        label='Min Confidence',
        help_text='Minimum confidence score (0-1)'
    )
    
    date_from = forms.DateField(
        required=False,
        widget=forms.DateInput(attrs={
            'class': 'form-control',
            'type': 'date'
        }),
        label='From Date'
    )
    
    date_to = forms.DateField(
        required=False,
        widget=forms.DateInput(attrs={
            'class': 'form-control',
            'type': 'date'
        }),
        label='To Date'
    )
    
    search = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={
            'class': 'form-control',
            'placeholder': 'Search text...'
        }),
        label='Search'
    )
