#!/usr/bin/env python
"""
Script to send a test notification to a specific user
Usage: python send_test_notification.py USER_ID [question_type]
"""
import os
import sys
import django

# Setup Django
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'worktimeapp.settings')
django.setup()

from ml_service.push_service import PushNotificationService
from ml_service.models import UserPattern

def send_test_notification(user_id: str, question_type: str = None):
    """Send a test notification to a user"""
    push_service = PushNotificationService()
    
    if question_type:
        # Send stamp reminder notification
        try:
            pattern = UserPattern.objects.get(user_id=user_id, question_type=question_type)
            typical_time_str = pattern.average_time.strftime('%H:%M')
            success, title, body = push_service.send_smart_reminder(user_id, question_type, typical_time_str)
            
            if success:
                print(f"✓ Successfully sent stamp reminder notification!")
                print(f"  Title: {title}")
                print(f"  Body: {body}")
            else:
                print("✗ Failed to send notification")
        except UserPattern.DoesNotExist:
            print(f"✗ Pattern not found for user {user_id}, question_type {question_type}")
            print("  Available question_types: clock_in, clock_out, lunch_in, lunch_out, break_in, break_out")
    else:
        # Send generic test notification
        success = push_service.send_notification(
            user_id=user_id,
            title='🧪 Test Notification',
            body='This is a test notification from Flexwise',
            data={'test': 'true'}
        )
        
        if success:
            print("✓ Successfully sent test notification!")
        else:
            print("✗ Failed to send notification")

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print("Usage: python send_test_notification.py USER_ID [question_type]")
        print("\nExamples:")
        print("  python send_test_notification.py 85138da8-1926-45ca-a907-162f9075e86c")
        print("  python send_test_notification.py 85138da8-1926-45ca-a907-162f9075e86c clock_out")
        sys.exit(1)
    
    user_id = sys.argv[1]
    question_type = sys.argv[2] if len(sys.argv) > 2 else None
    
    send_test_notification(user_id, question_type)

