-- Erstelle die ligen Tabelle
CREATE TABLE IF NOT EXISTS ligen (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Erstelle die mappools Tabelle
CREATE TABLE IF NOT EXISTS mappools (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    season VARCHAR(50) NOT NULL,
    liga_id INT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (liga_id) REFERENCES ligen(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Erstelle die mappool_maps Tabelle für die n:m Beziehung
CREATE TABLE IF NOT EXISTS mappool_maps (
    id INT AUTO_INCREMENT PRIMARY KEY,
    mappool_id INT NOT NULL,
    map_id INT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (mappool_id) REFERENCES mappools(id) ON DELETE CASCADE,
    FOREIGN KEY (map_id) REFERENCES Map(id) ON DELETE CASCADE,
    UNIQUE KEY unique_mappool_map (mappool_id, map_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
