SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

-- --------------------------------------------------------

CREATE TABLE user (
    user_id INT AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    street VARCHAR(100),
    house_number VARCHAR(10),
    postal_code VARCHAR(10),
    city VARCHAR(50),
    country VARCHAR(50),
    phone VARCHAR(20),
    email VARCHAR(100) UNIQUE,
    is_admin BOOLEAN DEFAULT FALSE,
    valid_until DATETIME NOT NULL DEFAULT '3025-01-01 00:00:00',
    password VARCHAR(255)
);


CREATE TABLE location (
    location_id INT AUTO_INCREMENT PRIMARY KEY,
    street VARCHAR(100),
    house_number VARCHAR(10),
    postal_code VARCHAR(10),
    city VARCHAR(50),
    country VARCHAR(50),
    phone VARCHAR(20),
    email VARCHAR(100)
);


CREATE TABLE event (
    event_id INT AUTO_INCREMENT PRIMARY KEY,
    location_id INT,
    start_date DATE,
    end_date DATE,
    name VARCHAR(100),
    description TEXT,
    max_tickets INT,
    ticket_price DECIMAL(5,2),
    FOREIGN KEY (location_id) REFERENCES location(location_id)
);


CREATE TABLE ticket (
    ticket_id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT,
    event_id INT,
    purchase_date DATE,
    valid_until DATE,
    FOREIGN KEY (user_id) REFERENCES user(user_id),
    FOREIGN KEY (event_id) REFERENCES event(event_id)
);


CREATE TABLE voucher (
    voucher_id INT AUTO_INCREMENT PRIMARY KEY,
    code VARCHAR(50) UNIQUE,
    discount INT CHECK (discount BETWEEN 0 AND 100),
    event_id INT,
    valid_until DATE,
    FOREIGN KEY (event_id) REFERENCES event(event_id)
);


CREATE TABLE news (
    news_id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100),
    description TEXT,
    date DATE
);



-- User-Daten (Passwort: passwort123)
INSERT INTO user (first_name, last_name, street, house_number, postal_code, city, country, phone, email, is_admin, password)
VALUES
    ('Max', 'Muster', 'Musterstraße', '1', '12345', 'Musterstadt', 'Deutschland', '0123456789', 'max@muster.de', FALSE, '$2y$10$VAj.C0XHPUxV4oXS6b79aumlg5fBMPPx5FPqgkQSIQeBLh0WtYmKy'),
    ('Anna', 'Beispiel', 'Beispielweg', '5a', '54321', 'Beispielstadt', 'Deutschland', '0987654321', 'anna@beispiel.de', TRUE, '$2y$10$cnPBpkvLbdpDxzYvxlQg9uVp5y8ggr2SWL8NAMg9zk.3QnnEl.MGq');

-- Standort-Daten
INSERT INTO location (street, house_number, postal_code, city, country, phone, email)
VALUES
    ('Galeriestraße', '10', '10115', 'Berlin', 'Deutschland', '030123456', 'kontakt@galerie-berlin.de'),
    ('Kunstallee', '22b', '50667', 'Köln', 'Deutschland', '0221123456', 'info@kunst-koeln.de');

-- Ausstellung-Daten
INSERT INTO event (location_id, start_date, end_date, name, description, max_tickets, ticket_price)
VALUES
    (1, '2025-07-01', '2025-08-31', 'Moderne Meisterwerke', 'Eine Sammlung moderner Kunstwerke aus Europa.', 200, 19.99),
    (2, '2025-09-10', '2025-10-20', 'Kunst der Antike', 'Ausstellung antiker Skulpturen und Gemälde.', 150, 39.99);

-- Gutschein-Daten
INSERT INTO voucher (code, discount, event_id, valid_until)
VALUES
    ('SOMMER2025', 15, 1, '2025-08-31'),
    ('HERBST25', 25, 2, '2025-10-15');

-- Ticket-Daten
INSERT INTO ticket (user_id, event_id, purchase_date, valid_until)
VALUES
    (1, 1, '2025-06-01', '2025-07-15'),
    (2, 2, '2025-06-05', '2025-09-15');

-- News-Daten
INSERT INTO news (name, description, date)
VALUES
    ('Neuer Standort eröffnet', 'Unsere Galerie in Köln ist jetzt geöffnet!', '2025-06-01'),
    ('Frühbucher-Rabatt', 'Sichern Sie sich jetzt 15% Rabatt auf unsere Sommerausstellung.', '2025-05-20');
