import os
import django

# Setup Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'worktimeapp.settings')
django.setup()

# 2. Import the WorkBalance model
from worktimeservice.models import WorkBalance
from datetime import date

# 3. Query for the specific user and date
work_balances = WorkBalance.objects.filter(
    user_id='edd631c63c1848c681244f5c7c868801',
    date=date(2025, 12, 10)
)

# 4. Check how many records exist (should be 1, but might be more if duplicates)
print(f"Found {work_balances.count()} record(s)")

# 5. List all records with their IDs and values
for wb in work_balances:
    print(f"ID: {wb.id}, total_work_seconds: {wb.total_work_seconds}, "
          f"regular_work_seconds: {wb.regular_work_seconds}, "
          f"updated_at: {wb.updated_at}")

# 6. Get the most recent record (by updated_at)
most_recent = work_balances.order_by('-updated_at', '-id').first()
if most_recent:
    print(f"\nMost recent record:")
    print(f"ID: {most_recent.id}")
    print(f"total_work_seconds: {most_recent.total_work_seconds} ({most_recent.total_work_seconds/3600:.2f} hours)")
    print(f"regular_work_seconds: {most_recent.regular_work_seconds}")
    print(f"net_work_seconds: {most_recent.net_work_seconds}")
    print(f"updated_at: {most_recent.updated_at}")
