-- POSBase Business Configuration Database Schema
-- Business-specific tables for general business operations
-- Multi-Business Architecture with Business Code Prefixing

SET FOREIGN_KEY_CHECKS = 0;

-- 1. BUSINESS SETTINGS TABLE
CREATE TABLE IF NOT EXISTS `{business_code}_business_settings` (
  `setting_id` int(11) NOT NULL AUTO_INCREMENT,
  `setting_key` varchar(100) NOT NULL,
  `setting_value` text NOT NULL,
  `setting_type` enum('string','boolean','number','json') NOT NULL DEFAULT 'string',
  `setting_group` int(11) NOT NULL DEFAULT 1 COMMENT '1=POS Settings, 2=Receipt Settings, 3=Printer Settings, 4=Staff Settings, 5=Inventory Settings',
  `setting_title` varchar(200) NOT NULL,
  `setting_description` varchar(500) DEFAULT NULL,
  `setting_text` varchar(200) DEFAULT NULL COMMENT 'Placeholder text for inputs',
  `setting_order` int(11) NOT NULL DEFAULT 0,
  `is_required` tinyint(1) NOT NULL DEFAULT 0,
  `setting_options` text DEFAULT NULL COMMENT 'JSON string for dropdown/radio options',
  `description` varchar(255) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`setting_id`),
  UNIQUE KEY `unique_setting_key` (`setting_key`),
  INDEX `idx_setting_group` (`setting_group`),
  INDEX `idx_setting_order` (`setting_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 2. BUSINESS LOCATIONS TABLE
CREATE TABLE IF NOT EXISTS `{business_code}_locations` (
  `location_id` int(11) NOT NULL AUTO_INCREMENT,
  `location_name` varchar(100) NOT NULL,
  `location_address` text DEFAULT NULL,
  `location_phone` varchar(20) DEFAULT NULL,
  `location_email` varchar(100) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `is_default` tinyint(1) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`location_id`),
  KEY `idx_location_name` (`location_name`),
  KEY `idx_is_active` (`is_active`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Insert default location
INSERT INTO `{business_code}_locations` (`location_name`, `is_default`) 
VALUES ('Main Location', 1);

SET FOREIGN_KEY_CHECKS = 1; 