# -*- coding: utf-8 -*-
"""
Notifications App

This Django app provides a comprehensive notification system for the AdTlas project.
It handles both in-app notifications and email notifications with support for
asynchronous delivery using Celery.

Features:
    - In-app notifications with real-time updates
    - Email notifications with customizable templates
    - Notification preferences and settings
    - Bulk notification sending
    - Notification history and tracking
    - Template-based notification rendering
    - Priority-based notification queuing
    - Notification categories and types
    - User notification preferences
    - Read/unread status tracking
    - Notification archiving and cleanup

Key Models:
    - NotificationType: Defines types of notifications
    - Notification: Individual notification instances
    - NotificationPreference: User notification preferences
    - NotificationTemplate: Email and in-app templates
    - NotificationQueue: Queue for batch processing

Key Views:
    - NotificationListView: List user notifications
    - NotificationDetailView: View notification details
    - NotificationPreferencesView: Manage notification settings
    - NotificationAPIView: REST API for notifications
    - MarkAsReadView: Mark notifications as read
    - NotificationStatsView: Notification statistics

Key Services:
    - NotificationService: Core notification logic
    - EmailService: Email notification handling
    - TemplateService: Template rendering
    - PreferenceService: User preference management

Celery Tasks:
    - send_notification_task: Send individual notifications
    - send_bulk_notifications_task: Send bulk notifications
    - cleanup_old_notifications_task: Clean up old notifications
    - process_notification_queue_task: Process queued notifications

Usage Examples:
    # Send a simple notification
    from apps.notifications.services import NotificationService
    
    NotificationService.send_notification(
        user=user,
        title='Welcome!',
        message='Welcome to AdTlas',
        notification_type='welcome'
    )
    
    # Send email notification
    NotificationService.send_email_notification(
        user=user,
        template='password_reset',
        context={'reset_link': 'https://example.com/reset'}
    )
    
    # Send bulk notifications
    NotificationService.send_bulk_notifications(
        users=User.objects.filter(is_active=True),
        title='System Maintenance',
        message='Scheduled maintenance tonight',
        notification_type='system'
    )

Author: AdTlas Development Team
Version: 1.0.0
Last Updated: 2024
"""

default_app_config = 'apps.notifications.apps.NotificationsConfig'

# Version information
__version__ = '1.0.0'
__author__ = 'AdTlas Development Team'

# App metadata
APP_NAME = 'notifications'
APP_VERBOSE_NAME = 'Notifications'
APP_DESCRIPTION = 'Comprehensive notification system with in-app and email support'

# Notification types
NOTIFICATION_TYPES = {
    'system': {
        'name': 'System Notifications',
        'description': 'System-wide announcements and updates',
        'icon': 'fas fa-cog',
        'color': 'primary',
        'default_enabled': True,
    },
    'security': {
        'name': 'Security Alerts',
        'description': 'Security-related notifications and alerts',
        'icon': 'fas fa-shield-alt',
        'color': 'danger',
        'default_enabled': True,
    },
    'account': {
        'name': 'Account Updates',
        'description': 'Account-related notifications',
        'icon': 'fas fa-user',
        'color': 'info',
        'default_enabled': True,
    },
    'activity': {
        'name': 'Activity Notifications',
        'description': 'User activity and interaction notifications',
        'icon': 'fas fa-bell',
        'color': 'success',
        'default_enabled': False,
    },
    'marketing': {
        'name': 'Marketing Communications',
        'description': 'Promotional and marketing notifications',
        'icon': 'fas fa-bullhorn',
        'color': 'warning',
        'default_enabled': False,
    },
    'welcome': {
        'name': 'Welcome Messages',
        'description': 'Welcome and onboarding notifications',
        'icon': 'fas fa-hand-wave',
        'color': 'success',
        'default_enabled': True,
    },
}

# Notification priorities
NOTIFICATION_PRIORITIES = {
    'low': {
        'name': 'Low Priority',
        'value': 1,
        'color': 'secondary',
        'delay_minutes': 60,  # Can be delayed up to 1 hour
    },
    'normal': {
        'name': 'Normal Priority',
        'value': 2,
        'color': 'primary',
        'delay_minutes': 15,  # Can be delayed up to 15 minutes
    },
    'high': {
        'name': 'High Priority',
        'value': 3,
        'color': 'warning',
        'delay_minutes': 5,   # Can be delayed up to 5 minutes
    },
    'urgent': {
        'name': 'Urgent',
        'value': 4,
        'color': 'danger',
        'delay_minutes': 0,   # Send immediately
    },
}

# Notification delivery methods
DELIVERY_METHODS = {
    'in_app': {
        'name': 'In-App Notifications',
        'description': 'Notifications displayed within the application',
        'enabled': True,
    },
    'email': {
        'name': 'Email Notifications',
        'description': 'Notifications sent via email',
        'enabled': True,
    },
    'sms': {
        'name': 'SMS Notifications',
        'description': 'Notifications sent via SMS (future feature)',
        'enabled': False,
    },
    'push': {
        'name': 'Push Notifications',
        'description': 'Browser push notifications (future feature)',
        'enabled': False,
    },
}

# Default notification settings
DEFAULT_SETTINGS = {
    'max_notifications_per_user': 1000,
    'notification_retention_days': 90,
    'email_batch_size': 100,
    'notification_queue_batch_size': 50,
    'cleanup_interval_hours': 24,
    'rate_limit_per_minute': 10,
    'enable_real_time_updates': True,
    'enable_email_notifications': True,
    'default_email_template': 'default',
    'unread_notification_limit': 100,
}

# Template contexts
TEMPLATE_CONTEXTS = {
    'base': {
        'site_name': 'AdTlas',
        'site_url': 'https://adtlas.com',
        'support_email': 'support@adtlas.com',
        'company_name': 'AdTlas Inc.',
    },
    'user': [
        'first_name',
        'last_name',
        'email',
        'username',
        'full_name',
    ],
    'notification': [
        'title',
        'message',
        'created_at',
        'notification_type',
        'priority',
        'action_url',
    ],
}

# Error messages
ERROR_MESSAGES = {
    'user_not_found': 'User not found for notification delivery',
    'template_not_found': 'Notification template not found',
    'invalid_notification_type': 'Invalid notification type specified',
    'delivery_failed': 'Failed to deliver notification',
    'rate_limit_exceeded': 'Notification rate limit exceeded',
    'preference_not_found': 'User notification preferences not found',
    'template_render_error': 'Error rendering notification template',
    'email_send_error': 'Error sending email notification',
    'bulk_send_error': 'Error sending bulk notifications',
    'queue_processing_error': 'Error processing notification queue',
}

# Success messages
SUCCESS_MESSAGES = {
    'notification_sent': 'Notification sent successfully',
    'bulk_notifications_queued': 'Bulk notifications queued for delivery',
    'preferences_updated': 'Notification preferences updated',
    'notification_marked_read': 'Notification marked as read',
    'notifications_archived': 'Notifications archived successfully',
    'template_created': 'Notification template created',
    'cleanup_completed': 'Notification cleanup completed',
}

# API response codes
API_RESPONSE_CODES = {
    'NOTIFICATION_SENT': 'NOTIFICATION_SENT',
    'NOTIFICATION_QUEUED': 'NOTIFICATION_QUEUED',
    'NOTIFICATION_FAILED': 'NOTIFICATION_FAILED',
    'PREFERENCES_UPDATED': 'PREFERENCES_UPDATED',
    'INVALID_REQUEST': 'INVALID_REQUEST',
    'RATE_LIMITED': 'RATE_LIMITED',
    'TEMPLATE_ERROR': 'TEMPLATE_ERROR',
    'USER_NOT_FOUND': 'USER_NOT_FOUND',
}

# Logging configuration
LOGGING_CONFIG = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
            'style': '{',
        },
        'simple': {
            'format': '{levelname} {message}',
            'style': '{',
        },
    },
    'handlers': {
        'file': {
            'level': 'INFO',
            'class': 'logging.FileHandler',
            'filename': 'logs/notifications.log',
            'formatter': 'verbose',
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple',
        },
    },
    'loggers': {
        'apps.notifications': {
            'handlers': ['file', 'console'],
            'level': 'INFO',
            'propagate': True,
        },
    },
}