-- Photo imports + OCR/detections from browser, Telegram, NAS upload
CREATE TABLE IF NOT EXISTS photo_imports (
    id SERIAL PRIMARY KEY,
    source VARCHAR(64) NOT NULL DEFAULT 'upload',
    filename VARCHAR(512),
    storage_path VARCHAR(1024),
    image_b64 TEXT NOT NULL,
    ocr_text TEXT,
    detections JSONB DEFAULT '[]'::jsonb,
    extracted_items JSONB DEFAULT '[]'::jsonb,
    metadata JSONB DEFAULT '{}'::jsonb,
    session_id INTEGER REFERENCES browser_sessions(id) ON DELETE SET NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_photo_imports_source ON photo_imports(source);
CREATE INDEX IF NOT EXISTS idx_photo_imports_created ON photo_imports(created_at DESC);
