-- Datenbank erstellen (falls nicht durch Docker-Umgebung bereits erstellt)
CREATE DATABASE IF NOT EXISTS testdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE testdb;

-- Bank-Tabelle erstellen
CREATE TABLE IF NOT EXISTS bank (
    iban VARCHAR(34) PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    passwd VARCHAR(255) NOT NULL,
    balance DECIMAL(10, 2) DEFAULT 0.00,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_name (name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Transaktions-Tabelle erstellen
CREATE TABLE IF NOT EXISTS transf (
    sender VARCHAR(34) NOT NULL,
    recipient VARCHAR(34) NOT NULL,
    amount DECIMAL(10, 2) NOT NULL,
    time INT UNSIGNED NOT NULL,
    text VARCHAR(500) DEFAULT '',
    PRIMARY KEY (sender, recipient, time),
    INDEX idx_sender (sender, time),
    INDEX idx_recipient (recipient, time),
    INDEX idx_time (time),
    FOREIGN KEY (sender) REFERENCES bank(iban) ON DELETE CASCADE,
    FOREIGN KEY (recipient) REFERENCES bank(iban) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Test-Accounts erstellen (Passwort: "test123" für alle)
INSERT INTO bank (iban, name, passwd, balance) VALUES
('DE1234', 'Max Mustermann', '$2y$10$YourHashedPasswordHere1', 5000.00),
('DE5678', 'Lisa Schmidt', '$2y$10$YourHashedPasswordHere2', 3500.00),
('DE9012', 'Thomas Müller', '$2y$10$YourHashedPasswordHere3', 12000.00)
ON DUPLICATE KEY UPDATE balance=balance;

