# -*- coding: utf-8 -*-
import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')

from sqlalchemy import create_engine, text

pg = create_engine('postgresql://admin:trajet6640@192.168.0.87:5432/apdb_master').connect()

# 안텔민킹 RAG 정보
apc = '0230237810109'
print(f'=== 안텔민킹 ({apc}) RAG 정보 ===\n')

result = pg.execute(text(f"""
    SELECT 
        product_name,
        llm_pharm->>'사용가능 동물' as target_animals,
        llm_pharm->>'분류' as category,
        llm_pharm->>'체중/부위' as dosage_weight,
        llm_pharm->>'월령금기' as age_restriction
    FROM apc
    WHERE apc = '{apc}'
"""))

row = result.fetchone()
if row:
    print(f'제품명: {row.product_name}')
    print(f'사용가능 동물: {row.target_animals}')
    print(f'분류: {row.category}')
    print(f'체중/용량: {row.dosage_weight}')
    print(f'월령금기: {row.age_restriction}')

# efficacy_effect도 확인
result2 = pg.execute(text(f"""
    SELECT efficacy_effect FROM apc WHERE apc = '{apc}'
"""))
row2 = result2.fetchone()
if row2 and row2.efficacy_effect:
    print(f'\n효능/효과 (원문 일부):')
    print(row2.efficacy_effect[:500])

pg.close()
