#!/usr/bin/env python3
"""
Verify that the date generation fix is working correctly
"""

from datetime import datetime, timezone
from storage.config import load_config_from_env
from storage.s3_adapter import S3Storage

def test_date_generation():
    """Test the date generation for S3 paths"""
    print("🧪 Testing S3 date generation...")
    
    # Test the timestamp prefix method
    now = datetime.now(timezone.utc)
    timestamp_prefix = now.strftime("%Y/%m/%d")
    
    print(f"🕐 Current UTC time: {now}")
    print(f"📅 Generated timestamp prefix: {timestamp_prefix}")
    
    # Test with S3Storage
    try:
        cfg = load_config_from_env()
        s3 = S3Storage(cfg, no_aws=True)  # Use no_aws mode for testing
        
        # Test the _timestamp_prefix method
        prefix = s3._timestamp_prefix()
        print(f"🔧 S3Storage._timestamp_prefix(): {prefix}")
        
        # Test put_json_with_url method
        test_url = "https://example.com/test"
        test_payload = {"test": "data", "timestamp": datetime.now().isoformat()}
        
        print(f"\n🧪 Testing put_json_with_url...")
        s3_path = s3.put_json_with_url(test_url, test_payload)
        print(f"📁 Generated S3 path: {s3_path}")
        
        # Verify the path contains today's date
        current_date = datetime.now().strftime("%Y/%m/%d")
        if current_date in s3_path:
            print(f"✅ Date generation is working correctly!")
            print(f"   Expected date: {current_date}")
            print(f"   Found in path: {s3_path}")
        else:
            print(f"❌ Date generation issue!")
            print(f"   Expected date: {current_date}")
            print(f"   Generated path: {s3_path}")
            
    except Exception as e:
        print(f"❌ Error testing S3Storage: {e}")
        import traceback
        print(f"Full error: {traceback.format_exc()}")

if __name__ == "__main__":
    test_date_generation()
