import sqlite3

conn = sqlite3.connect('instance/swiftcart_cloud.db')
c = conn.cursor()

try:
    c.execute('''
        CREATE TABLE khata_account (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            customer_name VARCHAR(150) NOT NULL,
            phone VARCHAR(50) UNIQUE NOT NULL,
            balance FLOAT DEFAULT 0.0
        )
    ''')
    print("KhataAccount table created successfully!")
except Exception as e:
    print(f"Error KhataAccount: {e}")

try:
    c.execute('''
        CREATE TABLE khata_transaction (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            khata_id INTEGER,
            amount FLOAT NOT NULL,
            t_type VARCHAR(50),
            description VARCHAR(255),
            date DATETIME DEFAULT CURRENT_TIMESTAMP,
            FOREIGN KEY(khata_id) REFERENCES khata_account(id)
        )
    ''')
    print("KhataTransaction table created successfully!")
except Exception as e:
    print(f"Error KhataTransaction: {e}")

conn.commit()
conn.close()
