#  Copyright (c) 2020 Xavier Baró
#
#      This program 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.
#
#      This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
""" Providers notifications tasks module """
from django.utils import timezone

from tesla_ce import celery_app
from tesla_ce import models


@celery_app.task(ignore_result=True)
def send_provider_notifications():
    """
        Send notifications to providers
    """
    for notification in models.ProviderNotification.objects.filter(when__lte=timezone.now()):
        provider_notify.apply_async((notification.id,), queue=notification.provider.queue)


@celery_app.task(ignore_result=True)
def provider_notify(notification_id):
    """
        Process a provider notification
        :param notification_id: Notification ID
    """
    # Executed on provider
    pass
