"""
Forms for LLM Manager — DaisyUI-styled widgets.
"""

from django import forms

from .models import LLMApi, LLMModel


class LLMApiForm(forms.ModelForm):
    class Meta:
        model = LLMApi
        fields = [
            "name",
            "api_type",
            "base_url",
            "api_key",
            "is_active",
            "supports_streaming",
            "timeout_seconds",
            "max_retries",
        ]
        widgets = {
            "name": forms.TextInput(attrs={"class": "input input-bordered w-full"}),
            "api_type": forms.Select(attrs={"class": "select select-bordered w-full"}),
            "base_url": forms.URLInput(attrs={"class": "input input-bordered w-full"}),
            "api_key": forms.PasswordInput(
                attrs={"class": "input input-bordered w-full", "autocomplete": "off"},
                render_value=True,
            ),
            "is_active": forms.CheckboxInput(attrs={"class": "toggle toggle-primary"}),
            "supports_streaming": forms.CheckboxInput(attrs={"class": "toggle toggle-primary"}),
            "timeout_seconds": forms.NumberInput(attrs={"class": "input input-bordered w-full"}),
            "max_retries": forms.NumberInput(attrs={"class": "input input-bordered w-full"}),
        }


class LLMModelForm(forms.ModelForm):
    class Meta:
        model = LLMModel
        fields = [
            "api",
            "name",
            "display_name",
            "model_type",
            "context_window",
            "max_output_tokens",
            "vector_dimensions",
            "supports_cache",
            "supports_vision",
            "supports_multimodal",
            "supports_function_calling",
            "supports_json_mode",
            "input_cost_per_1k",
            "output_cost_per_1k",
            "cached_cost_per_1k",
            "is_active",
        ]
        widgets = {
            "api": forms.Select(attrs={"class": "select select-bordered w-full"}),
            "name": forms.TextInput(attrs={"class": "input input-bordered w-full"}),
            "display_name": forms.TextInput(attrs={"class": "input input-bordered w-full"}),
            "model_type": forms.Select(attrs={"class": "select select-bordered w-full"}),
            "context_window": forms.NumberInput(attrs={"class": "input input-bordered w-full"}),
            "max_output_tokens": forms.NumberInput(attrs={"class": "input input-bordered w-full"}),
            "vector_dimensions": forms.NumberInput(attrs={"class": "input input-bordered w-full"}),
            "supports_cache": forms.CheckboxInput(attrs={"class": "toggle toggle-primary"}),
            "supports_vision": forms.CheckboxInput(attrs={"class": "toggle toggle-primary"}),
            "supports_multimodal": forms.CheckboxInput(attrs={"class": "toggle toggle-primary"}),
            "supports_function_calling": forms.CheckboxInput(attrs={"class": "toggle toggle-primary"}),
            "supports_json_mode": forms.CheckboxInput(attrs={"class": "toggle toggle-primary"}),
            "input_cost_per_1k": forms.NumberInput(
                attrs={"class": "input input-bordered w-full", "step": "0.000001"}
            ),
            "output_cost_per_1k": forms.NumberInput(
                attrs={"class": "input input-bordered w-full", "step": "0.000001"}
            ),
            "cached_cost_per_1k": forms.NumberInput(
                attrs={"class": "input input-bordered w-full", "step": "0.000001"}
            ),
            "is_active": forms.CheckboxInput(attrs={"class": "toggle toggle-primary"}),
        }
