-- ==============================================================================
-- DigiMobiz - Seed Data
-- Roles, Permissions, Admin User, Settings, Expense Categories
-- ==============================================================================

USE digimobiz;

SET FOREIGN_KEY_CHECKS = 0;

-- ==============================================================================
-- 1. ROLES (7 roles)
-- ==============================================================================
TRUNCATE TABLE roles;
INSERT INTO roles (role_name, description, status) VALUES
('Super Admin',   'Full system access with all permissions', 1),
('Admin',         'Administrative access with most permissions', 1),
('Cashier',       'POS billing and sales operations', 1),
('Technician',    'Repair job management and technician panel', 1),
('Stock Manager', 'Product, category, brand and stock management', 1),
('Accountant',    'Financial, expense and report access', 1),
('Sales Person',  'Sales and customer management', 1);

-- ==============================================================================
-- 2. PERMISSIONS (18 permissions)
-- ==============================================================================
TRUNCATE TABLE permissions;
INSERT INTO permissions (permission_key, permission_name, module_name, description) VALUES
('dashboard_view',       'Dashboard View',        'Dashboard',   'Access dashboard and view statistics'),
('product_management',   'Product Management',    'Products',    'Add, edit, delete products'),
('category_management',  'Category Management',   'Products',    'Manage categories and brands'),
('stock_view',           'Stock View',            'Products',    'View IMEI stock and inventory'),
('supplier_management',  'Supplier Management',   'Suppliers',   'Manage suppliers'),
('purchase_management',  'Purchase Management',   'Suppliers',   'Create and manage purchase orders'),
('pos_access',           'POS Access',            'POS',         'Access POS billing system'),
('customer_management',  'Customer Management',   'Customers',   'Manage customers'),
('repair_management',    'Repair Management',     'Repairs',     'Manage repair jobs'),
('technician_panel',     'Technician Panel',      'Repairs',     'Access technician job panel'),
('warranty_management',  'Warranty Management',   'Warranty',    'Manage warranties and claims'),
('return_management',    'Return Management',     'Returns',     'Process returns and exchanges'),
('payment_view',         'Payment View',          'Finance',     'View payment records'),
('expense_management',   'Expense Management',    'Finance',     'Manage expenses'),
('report_view',          'Report View',           'Reports',     'Access all reports'),
('user_management',      'User Management',       'Admin',       'Manage users and roles'),
('settings_access',      'Settings Access',       'Admin',       'Access system settings'),
('role_management',      'Role Management',       'Admin',       'Manage roles and permissions');

-- ==============================================================================
-- 3. ROLE PERMISSIONS
-- Super Admin (id=1) gets all 18 permissions
-- ==============================================================================
TRUNCATE TABLE role_permissions;
INSERT INTO role_permissions (role_id, permission_id)
SELECT 1, id FROM permissions;

-- ==============================================================================
-- 4. USERS (default Super Admin)
-- Password: admin123 (bcrypt hash)
-- ==============================================================================
TRUNCATE TABLE users;
INSERT INTO users (role_id, name, email, phone, password, status) VALUES
(1, 'Super Admin', 'admin@example.com', '0770000000', '$2y$10$lgU.AkHD8bd1YfrGQnMehO0eY6bCPXxbi9byY1Ze5gTgq/FLh3MaG', 1);

-- ==============================================================================
-- 5. SETTINGS (10 default settings)
-- ==============================================================================
TRUNCATE TABLE settings;
INSERT INTO settings (setting_key, setting_value, setting_group) VALUES
('shop_name',           'DigiMobiz',              'general'),
('shop_address',        '123 Main Street, Colombo', 'general'),
('shop_phone',          '011 2 123 456',          'general'),
('shop_email',          'info@digimobiz.lk',      'general'),
('currency_symbol',     'Rs.',                    'general'),
('tax_name',            'VAT',                    'tax'),
('tax_rate',            '0',                      'tax'),
('invoice_footer',      'Thank you for your business!', 'invoice'),
('low_stock_threshold', '5',                      'general'),
('default_customer_id', '',                       'general');

-- ==============================================================================
-- 6. EXPENSE CATEGORIES (8 categories)
-- ==============================================================================
TRUNCATE TABLE expense_categories;
INSERT INTO expense_categories (category_name, description) VALUES
('Rent',              'Shop/office rental payments'),
('Utilities',         'Electricity, water, internet, phone bills'),
('Salaries',          'Employee salary and wages'),
('Marketing',         'Advertising and promotional expenses'),
('Transport',         'Delivery and transportation costs'),
('Maintenance',       'Equipment and shop maintenance'),
('Office Supplies',   'Stationery and office consumables'),
('Other',             'Miscellaneous expenses');

SET FOREIGN_KEY_CHECKS = 1;
