-- ========================================
-- BURGERSHOT QUICK SETUP - Szybka instalacja
-- Używa INSERT IGNORE dla uniknięcia duplikatów
-- ========================================

-- Tabela kategorii produktów
CREATE TABLE IF NOT EXISTS burgershot_categories (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL UNIQUE,
    name_pl VARCHAR(50) NOT NULL,
    icon VARCHAR(50) DEFAULT 'fas fa-utensils',
    display_order INT DEFAULT 0,
    is_active BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Tabela produktów
CREATE TABLE IF NOT EXISTS burgershot_products (
    id INT AUTO_INCREMENT PRIMARY KEY,
    category_id INT NOT NULL,
    name VARCHAR(100) NOT NULL UNIQUE,
    description TEXT,
    price DECIMAL(8,2) NOT NULL,
    calories INT DEFAULT 0,
    image VARCHAR(255) DEFAULT 'placeholder.png',
    is_popular BOOLEAN DEFAULT FALSE,
    is_available BOOLEAN DEFAULT TRUE,
    stock_quantity INT DEFAULT -1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- Tabela zamówień
CREATE TABLE IF NOT EXISTS burgershot_orders (
    id INT AUTO_INCREMENT PRIMARY KEY,
    order_number VARCHAR(20) NOT NULL UNIQUE,
    order_type ENUM('dine-in', 'takeaway') NOT NULL DEFAULT 'dine-in',
    status ENUM('pending', 'preparing', 'ready', 'completed', 'cancelled') DEFAULT 'pending',
    payment_method ENUM('card', 'cash', 'phone') NOT NULL,
    payment_status ENUM('pending', 'paid', 'refunded') DEFAULT 'pending',
    subtotal DECIMAL(10,2) NOT NULL,
    tax DECIMAL(10,2) NOT NULL,
    total DECIMAL(10,2) NOT NULL,
    customer_name VARCHAR(100),
    customer_phone VARCHAR(20),
    notes TEXT,
    kiosk_id VARCHAR(50),
    cashier_id INT,
    prepared_by VARCHAR(100),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    completed_at TIMESTAMP NULL
);

-- Tabela pozycji zamówienia
CREATE TABLE IF NOT EXISTS burgershot_order_items (
    id INT AUTO_INCREMENT PRIMARY KEY,
    order_id INT NOT NULL,
    product_id INT NOT NULL,
    product_name VARCHAR(100) NOT NULL,
    quantity INT NOT NULL DEFAULT 1,
    unit_price DECIMAL(8,2) NOT NULL,
    customizations JSON,
    total_price DECIMAL(10,2) NOT NULL,
    notes TEXT
);

-- Tabela promocji
CREATE TABLE IF NOT EXISTS burgershot_promotions (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    description TEXT,
    discount_type ENUM('percentage', 'fixed', 'bogo') NOT NULL,
    discount_value DECIMAL(8,2) NOT NULL,
    min_order_value DECIMAL(8,2) DEFAULT 0,
    promo_code VARCHAR(50) UNIQUE,
    applicable_products JSON,
    applicable_categories JSON,
    start_date DATE,
    end_date DATE,
    max_uses INT DEFAULT -1,
    current_uses INT DEFAULT 0,
    is_active BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Tabela statystyk dziennych
CREATE TABLE IF NOT EXISTS burgershot_daily_stats (
    id INT AUTO_INCREMENT PRIMARY KEY,
    stat_date DATE NOT NULL UNIQUE,
    total_orders INT DEFAULT 0,
    total_revenue DECIMAL(12,2) DEFAULT 0,
    avg_order_value DECIMAL(8,2) DEFAULT 0,
    most_sold_product_id INT,
    dine_in_orders INT DEFAULT 0,
    takeaway_orders INT DEFAULT 0,
    card_payments INT DEFAULT 0,
    cash_payments INT DEFAULT 0,
    phone_payments INT DEFAULT 0,
    peak_hour INT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- Tabela kiosków
CREATE TABLE IF NOT EXISTS burgershot_kiosks (
    id INT AUTO_INCREMENT PRIMARY KEY,
    kiosk_id VARCHAR(50) NOT NULL UNIQUE,
    location VARCHAR(100),
    is_online BOOLEAN DEFAULT TRUE,
    last_heartbeat TIMESTAMP,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Tabela pracowników Burgershot
CREATE TABLE IF NOT EXISTS burgershot_employees (
    id INT AUTO_INCREMENT PRIMARY KEY,
    employee_id VARCHAR(20) NOT NULL UNIQUE,
    name VARCHAR(100) NOT NULL,
    role ENUM('cashier', 'cook', 'shift_manager', 'manager', 'director') DEFAULT 'cashier',
    pin_code VARCHAR(10) NOT NULL,
    is_active BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- ========================================
-- WSTAW DANE (IGNORE = pomija duplikaty)
-- ========================================

-- Kategorie
INSERT IGNORE INTO burgershot_categories (name, name_pl, icon, display_order) VALUES
('burgers', 'Burgery', 'fas fa-burger', 1),
('meals', 'Zestawy', 'fas fa-box', 2),
('sides', 'Dodatki', 'fas fa-french-fries', 3),
('drinks', 'Napoje', 'fas fa-cup-straw-swooshing', 4),
('desserts', 'Desery', 'fas fa-ice-cream', 5);

-- Pracownicy (PIN: 1234 dla pracowników, 9999 dla managerów)
INSERT IGNORE INTO burgershot_employees (employee_id, name, role, pin_code) VALUES
('EMP001', 'John Smith', 'cook', '1234'),
('EMP002', 'Jane Doe', 'cashier', '1234'),
('EMP003', 'Mike Johnson', 'shift_manager', '1234'),
('MGR001', 'Sarah Williams', 'manager', '9999'),
('DIR001', 'Robert Brown', 'director', '9999');

-- Burgery
INSERT IGNORE INTO burgershot_products (category_id, name, description, price, calories, image, is_popular) VALUES
(1, 'Bleeder Burger', 'Klasyczny burger z podwójnym kotletem wołowym, serem, sałatą i sosem specjalnym', 5.99, 650, 'bleeder.png', TRUE),
(1, 'Heart Stopper', 'Najbardziej intensywny burger - potrójne mięso, bekon, ser, cebula', 8.99, 1100, 'heartstopper.png', TRUE),
(1, 'Money Shot', 'Premium burger z wagyu, truflami i złotą bułką', 12.99, 850, 'moneyshot.png', FALSE),
(1, 'Torpedo', 'Długi burger w stylu submarine z sosem BBQ', 7.49, 780, 'torpedo.png', FALSE),
(1, 'Meat Free', 'Burger wegetariański z kotletem roślinnym', 6.49, 420, 'meatfree.png', FALSE),
(1, 'Double Shot', 'Podwójny klasyk z podwójnym serem', 6.99, 720, 'doubleshot.png', TRUE);

-- Zestawy
INSERT IGNORE INTO burgershot_products (category_id, name, description, price, calories, image, is_popular) VALUES
(2, 'Zestaw Bleeder', 'Bleeder Burger + Średnie Frytki + Napój', 8.99, 1050, 'meal-bleeder.png', TRUE),
(2, 'Zestaw Heart Stopper', 'Heart Stopper + Duże Frytki + Napój XL', 12.99, 1650, 'meal-heartstopper.png', TRUE),
(2, 'Family Box', '4x Burger + 2x Duże Frytki + 4x Napój', 29.99, 3200, 'family-box.png', FALSE),
(2, 'Kids Meal', 'Mini Burger + Małe Frytki + Napój + Zabawka', 5.99, 480, 'kids-meal.png', FALSE);

-- Dodatki
INSERT IGNORE INTO burgershot_products (category_id, name, description, price, calories, image, is_popular) VALUES
(3, 'Frytki', 'Chrupiące złote frytki', 2.49, 340, 'fries.png', TRUE),
(3, 'Onion Rings', 'Chrupiące krążki cebulowe', 3.49, 410, 'onion-rings.png', FALSE),
(3, 'Nuggetsy', '6 sztuk złocistych nuggetsów z kurczaka', 4.49, 280, 'nuggets.png', TRUE),
(3, 'Cheese Bites', 'Gorące kąski serowe', 3.99, 350, 'cheese-bites.png', FALSE),
(3, 'Coleslaw', 'Świeża surówka coleslaw', 1.99, 180, 'coleslaw.png', FALSE);

-- Napoje
INSERT IGNORE INTO burgershot_products (category_id, name, description, price, calories, image, is_popular) VALUES
(4, 'Sprunk', 'Orzeźwiający napój cytrynowo-limonkowy', 1.99, 140, 'sprunk.png', TRUE),
(4, 'eCola', 'Klasyczna cola', 1.99, 150, 'ecola.png', TRUE),
(4, 'Orang-O-Tang', 'Napój pomarańczowy', 1.99, 160, 'orangotang.png', FALSE),
(4, 'Shake', 'Kremowy shake', 3.49, 420, 'shake.png', TRUE),
(4, 'Woda mineralna', 'Naturalna woda źródlana', 1.49, 0, 'water.png', FALSE),
(4, 'Kawa', 'Świeżo parzona kawa', 2.49, 5, 'coffee.png', FALSE);

-- Desery
INSERT IGNORE INTO burgershot_products (category_id, name, description, price, calories, image, is_popular) VALUES
(5, 'Lody Soft', 'Kremowe lody w rożku', 1.99, 200, 'soft-ice.png', TRUE),
(5, 'McFlurry', 'Lody z dodatkami', 3.49, 380, 'mcflurry.png', TRUE),
(5, 'Ciasto jabłkowe', 'Ciepłe ciasto z jabłkami', 2.49, 240, 'apple-pie.png', FALSE),
(5, 'Donut', 'Świeży donut z polewą', 1.49, 250, 'donut.png', FALSE),
(5, 'Sundae', 'Lody z polewą i bitą śmietaną', 2.99, 320, 'sundae.png', FALSE);

-- Promocje
INSERT IGNORE INTO burgershot_promotions (name, description, discount_type, discount_value, promo_code, start_date, end_date) VALUES
('Mega Deal', 'Bleeder Burger + Frytki + Napój za $8.99', 'fixed', 2.00, 'MEGADEAL', CURDATE(), DATE_ADD(CURDATE(), INTERVAL 30 DAY)),
('10% zniżki', '10% zniżki na całe zamówienie', 'percentage', 10.00, 'BURGERSHOT10', CURDATE(), DATE_ADD(CURDATE(), INTERVAL 14 DAY)),
('Darmowy deser', 'Kup 2 burgery, dostań darmowy deser', 'bogo', 0.00, NULL, CURDATE(), DATE_ADD(CURDATE(), INTERVAL 7 DAY));

SELECT 'Burgershot Quick Setup completed!' as message;
