import sqlite3

conn = sqlite3.connect('db/orders.db')
cur = conn.cursor()

# wholesaler_limits 테이블 생성
cur.execute('''
CREATE TABLE IF NOT EXISTS wholesaler_limits (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    wholesaler_id TEXT NOT NULL UNIQUE,
    
    -- 한도 설정
    monthly_limit INTEGER DEFAULT 0,        -- 월 한도 (원)
    warning_threshold REAL DEFAULT 0.9,     -- 경고 임계값 (90%)
    
    -- 우선순위
    priority INTEGER DEFAULT 1,             -- 1이 최우선
    
    -- 상태
    is_active INTEGER DEFAULT 1,
    
    -- 메타
    created_at TEXT DEFAULT CURRENT_TIMESTAMP,
    updated_at TEXT DEFAULT CURRENT_TIMESTAMP
)
''')

# 기본 데이터 삽입 (각 2000만원)
wholesalers = [
    ('geoyoung', 20000000, 0.9, 1),
    ('sooin', 20000000, 0.9, 2),
    ('baekje', 20000000, 0.9, 3),
]

for ws_id, limit, threshold, priority in wholesalers:
    cur.execute('''
        INSERT OR REPLACE INTO wholesaler_limits 
        (wholesaler_id, monthly_limit, warning_threshold, priority)
        VALUES (?, ?, ?, ?)
    ''', (ws_id, limit, threshold, priority))

conn.commit()

# 확인
cur.execute('SELECT * FROM wholesaler_limits')
print('=== wholesaler_limits 생성 완료 ===')
for row in cur.fetchall():
    print(row)

conn.close()
