from wtforms import StringField, SelectField, TextAreaField, BooleanField
from wtforms.validators import DataRequired, InputRequired, Length, Optional, URL
from app.forms import BaseForm, ContactInfoMixin


class WorkWithUsForm(BaseForm, ContactInfoMixin):
    """WTForm matching the Work With Us collaboration proposal markup."""
    
    organisation = StringField('Organisation', validators=[
        Optional(),
        Length(max=150, message="Organisation name cannot exceed 150 characters.")
    ])
    
    role = StringField('Role', validators=[
        Optional(),
        Length(max=100, message="Role cannot exceed 100 characters.")
    ])
    
    website = StringField('Website', validators=[
        Optional(),
        URL(message="Please enter a valid URL (e.g., https://example.com)."),
        Length(max=255, message="URL cannot exceed 255 characters.")
    ])
    
    collaboration_type = SelectField('Type of Collaboration', choices=[
        ('Technical Partnership', 'Technical Partnership'),
        ('Project Collaboration', 'Project Collaboration'),
        ('Research & Development', 'Research & Development'),
        ('Sponsorship & Community', 'Sponsorship & Community'),
        ('Volunteer with CodNesta', 'Volunteer with CodNesta'),
        ('Other', 'Other')
    ], validators=[
        DataRequired(message="Please select a collaboration type.")
    ])
    
    contribution = TextAreaField('Expected Contribution', validators=[
        DataRequired(message="Please describe what you bring or contribute."),
        Length(min=10, max=2000, message="Contribution details must be between 10 and 2000 characters.")
    ])
    
    support_requested = TextAreaField('Support Requested', validators=[
        DataRequired(message="Please detail the support you are requesting."),
        Length(min=10, max=2000, message="Support details must be between 10 and 2000 characters.")
    ])
    
    message = TextAreaField('Additional Notes', validators=[
        Optional(),
        Length(max=1000, message="Message cannot exceed 1000 characters.")
    ])
    
    agreement = BooleanField('Agreement', validators=[
        InputRequired(message="You must accept the terms to proceed.")
    ])

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Removes inherited privacy_consent field from BaseForm so WTForms doesn't look for it
        if 'privacy_consent' in self._fields:
            del self._fields['privacy_consent']