import json
import asyncio
import sys
sys.path.insert(0, '.')
from src.core.db.postgres_db import PostgresDb
from src.core.processor.asr import AsrResult
from src.core.processor.cut import CutResult
from src.worker.processor import ProcessorPool

async def test_chunk_storage():
    # Initialize database
    db = await PostgresDb::init()
    
    # Test ASR chunk storage
    asr_result = AsrResult(
        language="en",
        language_probability=0.95,
        segments=[
            {"start": 0.0, "end": 5.0, "text": "Hello world"},
            {"start": 5.0, "end": 10.0, "text": "This is a test"}
        ]
    )
    
    print("Testing ASR chunk storage...")
    try:
        await ProcessorPool.store_asr_chunks(db, "384b0ff44aaaa1f1", asr_result)
        print("ASR chunk storage succeeded")
    except Exception as e:
        print(f"ASR chunk storage failed: {e}")
    
    # Test CUT chunk storage
    cut_result = CutResult(
        scenes=[
            {"scene_number": 1, "start_time": 0.0, "end_time": 5.0, "start_frame": 0, "end_frame": 150},
            {"scene_number": 2, "start_time": 5.0, "end_time": 10.0, "start_frame": 151, "end_frame": 300}
        ]
    )
    
    print("\nTesting CUT chunk storage...")
    try:
        await ProcessorPool.store_cut_chunks(db, "384b0ff44aaaa1f1", cut_result)
        print("CUT chunk storage succeeded")
    except Exception as e:
        print(f"CUT chunk storage failed: {e}")

if __name__ == "__main__":
    asyncio.run(test_chunk_storage())
