from typing import List

from django import forms
from django.core.exceptions import ValidationError


class SearchForm(forms.Form):
    """Example of search form."""

    FORBIDDEN_WORDS: List[str] = ["lemon", "hat", "car"]
    query = forms.CharField(max_length=32, label="query", required=True)

    def clean_query(self) -> str:
        """
        Validate the query field.

        Returns:
            The value for the "cleaned" query field.

        """
        value: str = self.cleaned_data["query"]
        if value.lower() in self.FORBIDDEN_WORDS:
            raise ValidationError(f"Search term cannot be one of the following: {self.FORBIDDEN_WORDS}")
        return value
