-- Create settings table
CREATE TABLE IF NOT EXISTS `settings` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `setting_key` VARCHAR(100) NOT NULL UNIQUE,
  `setting_value` TEXT NOT NULL,
  `data_type` ENUM('STRING', 'NUMBER', 'BOOLEAN', 'JSON') DEFAULT 'STRING',
  `description` TEXT,
  `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;

-- Insert default settings
INSERT INTO `settings` (`setting_key`, `setting_value`, `data_type`, `description`) VALUES
('company_name', 'AZ SPORTS', 'STRING', 'Company name displayed on receipts and invoices'),
('company_address', '116, Vauxhall Street, Colombo 2', 'STRING', 'Company address'),
('company_phone', '+94 76 666 8869 | +94 76 322 8458', 'STRING', 'Company contact phone number'),
('company_email', 'azsports023@gmail.com', 'STRING', 'Company email address'),
('tax_rate', '0', 'NUMBER', 'Default tax rate percentage'),
('currency_symbol', '', 'STRING', 'Currency symbol for display'),
('low_stock_threshold', '10', 'NUMBER', 'Alert when stock falls below this quantity'),
('enable_notifications', 'true', 'BOOLEAN', 'Enable system notifications'),
('receipt_footer', 'Thank you for your business!', 'STRING', 'Footer text on receipts'),
('auto_backup', 'false', 'BOOLEAN', 'Enable automatic database backups'),
('printer_name', '', 'STRING', 'Thermal printer name (Windows: "POS-80", Linux: "/dev/usb/lp0")'),
('printer_type', 'NETWORK', 'STRING', 'Printer type: NETWORK, USB, SERIAL'),
('printer_ip', '', 'STRING', 'Network printer IP address (e.g., 192.168.1.100)'),
('printer_port', '9100', 'STRING', 'Network printer port (default: 9100 for ESC/POS)'),
('enable_auto_print', 'true', 'BOOLEAN', 'Enable automatic printing after invoice creation')
ON DUPLICATE KEY UPDATE
    `setting_value` = VALUES(`setting_value`),
    `description` = VALUES(`description`);
