# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later

from django import forms
from django.forms.widgets import NumberInput
from note_kfet.inputs import Autocomplete

from .models import Challenge, FamilyMembership, User, Family


class ChallengeForm(forms.ModelForm):
    """
    To update a challenge
    """
    class Meta:
        model = Challenge
        fields = ('name', 'description', 'points',)
        widgets = {
            "points": NumberInput()
        }


class FamilyForm(forms.ModelForm):
    class Meta:
        model = Family
        fields = ('name', 'description', )


class FamilyMembershipForm(forms.ModelForm):
    class Meta:
        model = FamilyMembership
        fields = ('user', )

        widgets = {
            "user":
                Autocomplete(
                    User,
                    attrs={
                        'api_url': '/api/user/',
                        'name_field': 'username',
                        'placeholder': 'Nom ...',
                    },
                )
        }
