# Foobar - a sport competition management software
# Copyright (c) 2026 Felipe Cuqueto Piekarz
# Copyright (c) 2026 Luiz Soneghet Nascimento
# Copyright (c) 2026 Rodolfo Ribeiro Gomes
#
# This file is part of Foobar.
#
# Foobar is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Foobar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Foobar.  If not, see <https://www.gnu.org/licenses/>.

from django import forms

from .models import Torneio,  ConfiguracaoTime,  Edicao

class CriarTorneioForm(forms.ModelForm):
    class Meta:
        model = Torneio
        exclude = ["", "slug"]
        widgets = {
            "descricao": forms.Textarea(attrs={"cols": 80, "rows": 20}),
        }
    def clean(self):
        super().clean()
        self.cleaned_data["edicao"] = Edicao.objects.get(pk=self.edicao_id)
        
    def save(self, *args, **kwargs):
        self.edicao = Edicao.objects.get(pk=self.edicao_id)
        return super().save(*args, **kwargs)
        
    def  set_edicao(self, edicao_id : int):
        self.edicao_id = edicao_id

class CriarConfiguracaoTimeForm(forms.ModelForm):
    class Meta:
        model = ConfiguracaoTime
        exclude = ["torneio"]
        widgets = {
            "obs": forms.Textarea(attrs={"cols": 80, "rows": 20}),
        }

class CriarConfiguracaoTimeNaipeForm(forms.ModelForm):
    class Meta:
        model = ConfiguracaoTime
        exclude = ["torneio",  "feminino_maximo",  "feminino_minimo",  "masculino_maximo",  "masculino_minimo"]
        widgets = {
            "obs": forms.Textarea(attrs={"cols": 80, "rows": 20}),
        }

class CriarChaveAcessoForm(forms.Form):
    nome_time = forms.CharField(label="Nome do time", max_length=50, min_length=3)

class CriarIntegranteForm(forms.Form):
    nome = forms.CharField(label="Nome do integrante", max_length=50, min_length=3)
    genero = forms.ChoiceField(label="Gênero", choices=[('M',  'Masculino'),  ('F',  'Feminino')])
