-- Erstelle die Datenbank
CREATE DATABASE IF NOT EXISTS NexusControl CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE NexusControl;

-- Erstelle die Spieler-Tabelle
CREATE TABLE IF NOT EXISTS players (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    elo INT NOT NULL DEFAULT 1500,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- Erstelle die Spiele-Tabelle
CREATE TABLE IF NOT EXISTS matches (
    id INT AUTO_INCREMENT PRIMARY KEY,
    player1_id INT NOT NULL,
    player2_id INT NOT NULL,
    player1_old_elo INT NOT NULL,
    player2_old_elo INT NOT NULL,
    player1_new_elo INT NOT NULL,
    player2_new_elo INT NOT NULL,
    winner ENUM('player1', 'player2', 'draw') NOT NULL,
    is_q_league BOOLEAN NOT NULL DEFAULT FALSE,
    match_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (player1_id) REFERENCES players(id),
    FOREIGN KEY (player2_id) REFERENCES players(id)
);

-- Füge Beispiel-Spieler ein
INSERT INTO players (name, elo) VALUES
    ('Douga\'an Valkaanier', 1500),
    ('Schlagimnacken', 1500),
    ('CataCtrofeLP', 1500),
    ('Nomarino', 1550),
    ('Cyrus', 1500),
    ('RaceHamster', 1500),
    ('DSP_Phillip', 1500),
    ('Chris P.Chicken', 1500);
