"""
Create high risk burnout scenario for testing
"""

import os
import sys
import django

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'worktimeapp.settings')
django.setup()

from datetime import datetime, date, timedelta
from stamps.models import Stamp
from user.models import User
from functions.models import Function
from ml_service.models import BurnoutNotification, BurnoutAnalysis
from django.utils import timezone

TEST_USER_ID = "575f8050-e027-4db9-9ff1-31e0b1b7dfad"

print("Creating HIGH RISK burnout scenario...")
try:
    user = User.objects.get(id=TEST_USER_ID)
except:
    print(f"User {TEST_USER_ID} not found")
    sys.exit(1)

# Get functions
clock_in_func = Function.objects.filter(question_type='clock_in').first()
clock_out_func = Function.objects.filter(question_type='clock_out').first()

if not clock_in_func or not clock_out_func:
    clock_in_func, _ = Function.objects.get_or_create(
        function_ref_id='clock_in_001',
        defaults={'name': 'Clock In', 'out': False, 'break_flag': False, 'pre_function': False, 'question_type': 'clock_in'}
    )
    clock_out_func, _ = Function.objects.get_or_create(
        function_ref_id='clock_out_001',
        defaults={'name': 'Clock Out', 'out': True, 'break_flag': False, 'pre_function': False, 'question_type': 'clock_out'}
    )

# Create 30 days of excessive work (11 hours/day, no breaks, weekends worked)
count = 0
for day in range(30):
    stamp_date = date.today() - timedelta(days=day)
    
    # Longer hours (11 hours instead of 10.5)
    clock_in = datetime.combine(stamp_date, datetime.strptime('06:00:00', '%H:%M:%S').time())
    clock_out = datetime.combine(stamp_date, datetime.strptime('17:30:00', '%H:%M:%S').time())
    
    Stamp.objects.update_or_create(
        user=user, date=stamp_date, time=clock_in.time(), stamp_function=clock_in_func.id,
        defaults={'description': f'High risk test - Day {day+1}', 'start_date': clock_in}
    )
    
    Stamp.objects.update_or_create(
        user=user, date=stamp_date, time=clock_out.time(), stamp_function=clock_out_func.id,
        defaults={'description': f'High risk test - Day {day+1}', 'start_date': clock_out}
    )
    
    count += 1

print(f"Created {count} days of stamps (11 hours/day, no breaks, including weekends)")

# Create high-risk notification directly
notif = BurnoutNotification.objects.create(
    user_id=TEST_USER_ID,
    notification_type='burnout_alert',
    title='CRITICAL: High Burnout Risk Detected',
    message='Your work patterns show 85/100 burnout risk. Take action immediately.\n\nSuggestion: Use available flex time to reduce workload',
    risk_score=85,
    recommendation={'balance_type': 'flex_time', 'action': 'Use 2.5h flex time to finish early'},
    is_read=False
)

print(f"\nCreated notification:")
print(f"Title: {notif.title}")
print(f"Message: {notif.message}")
print(f"Risk Score: {notif.risk_score}/100")
print(f"\nNotification ID: {notif.id}")
print("\nNOW CHECK YOUR APP - you should see a red badge on the bell!")

