"""
Add exchange rate weight columns to system_settings table
"""
import sqlite3

def upgrade():
    conn = sqlite3.connect('autonet.db')
    cursor = conn.cursor()

    # Check existing columns
    cursor.execute("PRAGMA table_info(system_settings)")
    columns = [col[1] for col in cursor.fetchall()]

    new_columns = [
        ('exchange_rate_weight_usd', 'FLOAT DEFAULT 0.0'),
        ('exchange_rate_weight_mnt', 'FLOAT DEFAULT 0.0'),
        ('exchange_rate_weight_rub', 'FLOAT DEFAULT 0.0'),
        ('exchange_rate_weight_cny', 'FLOAT DEFAULT 0.0'),
    ]

    for col_name, col_type in new_columns:
        if col_name not in columns:
            try:
                cursor.execute(f'ALTER TABLE system_settings ADD COLUMN {col_name} {col_type}')
                print(f'Added column: {col_name}')
            except Exception as e:
                print(f'Error adding {col_name}: {e}')
        else:
            print(f'Column {col_name} already exists')

    conn.commit()
    conn.close()
    print('Database migration complete!')

if __name__ == '__main__':
    upgrade()
