from . import models
from django.forms import ModelForm
from django.forms import TextInput


class AntiSpam(ModelForm):
    class Meta:
        model = models.GroupPreferences
        fields = ['combot_anti_spam_use',
                  'combot_anti_spam_notification',
                  ]
        labels = {
            'combot_anti_spam_use': 'Use Combot Anti-Spam System (CAS)',
            'combot_anti_spam_notification': 'Send message mentioning that a spammer was banned',
        }
        help_texts = {
            'combot_anti_spam_use': 'By doing so, you understand that you will have to comply with their conditions.',
            'combot_anti_spam_notification': 'Leave it empty to disable. Use {NAME} to display the known spammer\'s name instead; {GROUP} will be replaced for group\'s name.',
        }


class CAPTCHA(ModelForm):
    class Meta:
        model = models.GroupPreferences
        fields = ['captcha_use',
                  'captcha_chars',
                  'captcha_digits',
                  'captcha_timeout',
                  'captcha_attempts',
                  'captcha_first_message',
                  'captcha_retry_message',
                  'captcha_leave_mess',
                  ]
        labels = {
            'captcha_use': 'Use CAPTCHA on new members',
            'captcha_chars': 'Characters that will be used in the CAPTCHA',
            'captcha_digits': 'Length (in digits) of your CAPTCHA',
            'captcha_timeout': 'Maximum time (in seconds) to wait for someone to solve the CAPTCHA before kicking',
            'captcha_attempts': 'Maximum error count before kicking',
            'captcha_first_message': 'First CAPTCHA message, shown upon arrival',
            'captcha_retry_message': 'CAPTCHA messages, shown after mistaken attempts',
            'captcha_leave_mess': 'Do not erase CAPTCHAS and attempts',
        }
        help_texts = {
            'captcha_timeout': 'Failed attempts do not reset such timmer',
            'captcha_chars': 'Make sure all characters are distinct, such as lowercase "L", uppercase "i" and the number "1", and "oO0" (2 vowels, 1 number)',
            'captcha_first_message': '{NAME} will be replaced for user\'s name; {GROUP} will be replaced for group\'s name; {ATTEMPTS} will be replaced for the number of attempts the user has; {TIMEOUT} will be replaced for amount of seconds an user has to solve the CAPTCHA; up to 1000 characters',
            'captcha_retry_message': '{NAME} will be replaced for user\'s name; {GROUP} will be replaced for group\'s name; {ATTEMPTS} will be replaced for the number of remaining attempts the user has; {TIMEOUT} will be replaced for amount of seconds left an user has to solve the CAPTCHA; up to 1000 characters',
            'captcha_leave_mess': 'Might be spammy if checked',
        }


class Greetings(ModelForm):
    class Meta:
        model = models.GroupPreferences
        fields = ['join_message',
                  'leave_message',
                  ]
        help_texts = {
            'join_message': 'Leave blank to disable this feature; {NAME} will be replaced for user\'s name; {GROUP} will be replaced for group\'s name; will be delayed until Anti-Spam and CAPTCHA steps gets either completed or skipped',
            'leave_message': 'Leave blank to disable this feature; {NAME} will be replaced for user\'s name; {GROUP} will be replaced for group\'s name',
        }


class CannedMessage(ModelForm):
    class Meta:
        model = models.GroupCannedMessage
        fields = ['listen',
                  'reply_with',
                  ]
        help_texts = {
            'listen': 'Matches any part in a a larger message',
        }


class PlannedMessageTimezone(ModelForm):
    class Meta:
        model = models.GroupPreferences
        fields = ['planned_message_timezone',
                  ]
        labels = {
            'planned_message_timezone': 'Timezone',
        }


class PlannedMessage(ModelForm):
    class Meta:
        model = models.GroupPlannedMessage
        fields = ['tags',
                  'message',
                  ]
        widgets = {
            'tags': TextInput(),
        }
        help_texts = {
            'tags': 'Comma-sepparated and/or space-sepparated tags'
        }


class PlannedDispatch(ModelForm):
    class Meta:
        model = models.GroupPlannedDispatch
        fields = ['tags',
                  'day_sunday',
                  'day_monday',
                  'day_tuesday',
                  'day_wednesday',
                  'day_thursday',
                  'day_friday',
                  'day_saturday',
                  'time_start',
                  'time_end',
                  'time_repeat',
                  ]
        widgets = {
            'tags': TextInput(),
        }
        help_texts = {
            'tags': 'Comma-sepparated or space-sepparated tags'
        }


class PlannedMessageConfiguration(ModelForm):
    class Meta:
        model = models.GroupPreferences
        fields = ['planned_message_enabled',
                  'planned_message_issuer',
                  ]
        labels = {
            'planned_message_enabled': 'Is this module enabled?',
            'planned_message_issuer': 'Which bot will be used?',
        }


class AccessControlGrant(ModelForm):
    class Meta:
        model = models.GroupAccessControlGrant
        fields = ['allows',
                  ]
        labels = {
            'allows': 'Who else will you grant access to this panel?',
        }


class AccessControlUse(ModelForm):
    class Meta:
        model = models.GroupPreferences
        fields = ['access_control_use',
                  ]
        labels = {
            'access_control_use': 'Restrict access to bot\'s control panel to group\'s creator and trusted users?',
        }
        help_texts = {
            'access_control_use': 'If unchecked, any admin at your group will also be able to manage the bot.',
        }
