# Copyright (c) 2017 iXsystems, Inc.
# All rights reserved.
# This file is a part of TrueNAS
# and may not be copied and/or distributed
# without the express permission of iXsystems.

from django.utils.translation import ugettext as _

from freenasUI.system.alert import alertPlugins, Alert, BaseAlert
from freenasUI.system.models import Support


class IxAlert(BaseAlert):

    def run(self):
        available, support = Support.is_available()
        if available and support.enabled is None:
            return [Alert(
                Alert.WARN,
                _('The Proactive Support feature is not enabled. Please see the System -> Proactive Support tab.')
            )]
        elif support.is_enabled():
            # This is for people who had ix alert enabled before Proactive Support
            # feature and have not filled all the new fields.
            unfilled = []
            for field in Support._meta.fields:
                if not getattr(support, field.name):
                    unfilled.append(field)
            if unfilled:
                return [Alert(
                    Alert.WARN,
                    _('Please fill in these fields on the System -> Proactive Support tab: %s.') % ', '.join([str(i.verbose_name) for i in unfilled])
                )]


alertPlugins.register(IxAlert)
