# -*- coding: utf-8 -*-
import sqlite3

conn = sqlite3.connect('db/paai_logs.db')

# 테이블 목록
cursor = conn.execute("SELECT name FROM sqlite_master WHERE type='table'")
tables = cursor.fetchall()
print('테이블 목록:', [t[0] for t in tables])

# 로그 개수
count = conn.execute('SELECT COUNT(*) FROM paai_logs').fetchone()[0]
print(f'PAAI 로그 수: {count}개')

# 최근 로그
print('\n최근 로그 3개:')
recent = conn.execute('SELECT id, created_at, patient_name, status FROM paai_logs ORDER BY id DESC LIMIT 3').fetchall()
for r in recent:
    print(f'  #{r[0]} | {r[1]} | {r[2]} | {r[3]}')

# 피드백 통계
feedback = conn.execute('SELECT feedback_useful, COUNT(*) FROM paai_logs GROUP BY feedback_useful').fetchall()
print('\n피드백 통계:')
for f in feedback:
    label = '유용' if f[0] == 1 else ('아님' if f[0] == 0 else '미응답')
    print(f'  {label}: {f[1]}건')

conn.close()
