CREATE TABLE setting_categories (
    id INT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(100) NOT NULL,      -- e.g., 'Print Settings'
    code VARCHAR(50) UNIQUE NOT NULL -- e.g., 'print', 'sales'
);
CREATE TABLE settings (
    id INT PRIMARY KEY AUTO_INCREMENT,
    category_id INT NOT NULL,                         -- FK to setting_categories
    name VARCHAR(100) NOT NULL,                       -- e.g., 'Enable Receipt Printing'
    code VARCHAR(100) NOT NULL,                       -- e.g., 'enable_receipt'
    type ENUM('boolean', 'text', 'number', 'select'), -- for UI rendering
    value TEXT,                                       -- actual saved value
    default_value TEXT,
    description TEXT,
    is_active BOOLEAN DEFAULT TRUE,
    FOREIGN KEY (category_id) REFERENCES setting_categories(id)
);
CREATE TABLE setting_options (
    id INT PRIMARY KEY AUTO_INCREMENT,
    setting_id INT NOT NULL,                        -- FK to settings
    option_label VARCHAR(100),                      -- what to display in dropdown
    option_value VARCHAR(100),                      -- what gets stored
    FOREIGN KEY (setting_id) REFERENCES settings(id)
);
INSERT INTO setting_categories (name, code) 
VALUES ('Print Settings', 'print_settings');
INSERT INTO `settings` (`id`, `category_id`, `name`, `code`, `type`, `value`, `default_value`, `description`, `is_active`) VALUES (NULL, '1', 'Print Customer Name', 'print_cus_name', 'boolean', NULL, '1', 'Print Customer Name on Print', '1');


INSERT INTO setting_categories (name, code)
VALUES ('Integration', 'integration')
ON DUPLICATE KEY UPDATE name = VALUES(name);


INSERT INTO `settings` (`id`, `category_id`, `name`, `code`, `type`, `value`, `default_value`, `description`, `is_active`) VALUES (NULL, '1', 'Print KOT', 'print_kot', 'boolean', '1', '1', 'Print Kitchen Order Ticket (KOT)', '1');




CREATE TABLE kot_devices (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,           -- "Kitchen Printer", "Bar Printer", etc.
    connection_type ENUM('usb', 'lan') NOT NULL,
    printer_name VARCHAR(100),            -- Windows shared name or device name
    ip_address VARCHAR(100),              -- For LAN printers only
    is_active TINYINT(1) DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
