CREATE TABLE IF NOT EXISTS user_groups (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    permissions TEXT, -- JSON or comma-separated list of capabilities
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    group_id INT,
    username VARCHAR(255) NOT NULL UNIQUE,
    password VARCHAR(255) NOT NULL,
    full_name VARCHAR(255),
    email VARCHAR(255) UNIQUE,
    is_active BOOLEAN DEFAULT TRUE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (group_id) REFERENCES user_groups(id) ON DELETE SET NULL
);

-- Seed default groups
INSERT INTO user_groups (name, permissions) VALUES ('Administrator', 'all');
INSERT INTO user_groups (name, permissions) VALUES ('Manager', 'manage_orders,manage_products,manage_reports');
INSERT INTO user_groups (name, permissions) VALUES ('Cashier', 'pos,manage_orders');
INSERT INTO user_groups (name, permissions) VALUES ('Waiter', 'pos');

-- Seed default admin user (password: admin123)
-- Using PHP to hash the password properly would be better, but for initial seeding we can use a placeholder if we have a setup script.
-- Let's just create the tables for now.
