-- Comprehensive Permission Seeding Script
-- This script seeds all permissions for the RBAC system
-- Module IDs: 1=Supply Chain, 2=Operations, 3=MD, 4=Accounts, 5=Audit, 6=HR, 8=CRM
-- Store ID: 0 for global permissions (can be overridden per store later)

-- Note: Chat module has no permissions (all users have access)
-- Note: DMS only has approval/version control permissions (most features are public)

-- ============================================
-- SUPPLY CHAIN MODULE (module_id: 1)
-- ============================================
INSERT IGNORE INTO permissions (module_id, store_id, name, description) VALUES
(1, 0, 'SUPPLY_CHAIN_DASHBOARD_VIEW', 'View Supply Chain dashboard'),
(1, 0, 'SUPPLY_CHAIN_PROCUREMENT_VIEW', 'View procurement records'),
(1, 0, 'SUPPLY_CHAIN_PROCUREMENT_CREATE', 'Create procurement records'),
(1, 0, 'SUPPLY_CHAIN_PROCUREMENT_EDIT', 'Edit procurement records'),
(1, 0, 'SUPPLY_CHAIN_PROCUREMENT_DELETE', 'Delete procurement records'),
(1, 0, 'SUPPLY_CHAIN_PROCUREMENT_APPROVE', 'Approve procurement requests'),
(1, 0, 'SUPPLY_CHAIN_PURCHASE_ORDER_VIEW', 'View purchase orders'),
(1, 0, 'SUPPLY_CHAIN_PURCHASE_ORDER_CREATE', 'Create purchase orders'),
(1, 0, 'SUPPLY_CHAIN_PURCHASE_ORDER_EDIT', 'Edit purchase orders'),
(1, 0, 'SUPPLY_CHAIN_PURCHASE_ORDER_APPROVE', 'Approve purchase orders'),
(1, 0, 'SUPPLY_CHAIN_SUPPLIER_VIEW', 'View suppliers'),
(1, 0, 'SUPPLY_CHAIN_SUPPLIER_CREATE', 'Create suppliers'),
(1, 0, 'SUPPLY_CHAIN_SUPPLIER_EDIT', 'Edit suppliers'),
(1, 0, 'SUPPLY_CHAIN_SUPPLIER_DELETE', 'Delete suppliers'),
(1, 0, 'SUPPLY_CHAIN_SUPPLIER_MANAGE', 'Full supplier management'),
(1, 0, 'SUPPLY_CHAIN_INVENTORY_VIEW', 'View inventory'),
(1, 0, 'SUPPLY_CHAIN_INVENTORY_CREATE', 'Create inventory records'),
(1, 0, 'SUPPLY_CHAIN_INVENTORY_EDIT', 'Edit inventory records'),
(1, 0, 'SUPPLY_CHAIN_INVENTORY_DELETE', 'Delete inventory records'),
(1, 0, 'SUPPLY_CHAIN_INVENTORY_ADJUST', 'Adjust inventory levels'),
(1, 0, 'SUPPLY_CHAIN_STOCK_VIEW', 'View stock'),
(1, 0, 'SUPPLY_CHAIN_STOCK_CREATE', 'Create stock records'),
(1, 0, 'SUPPLY_CHAIN_STOCK_EDIT', 'Edit stock records'),
(1, 0, 'SUPPLY_CHAIN_STOCK_TRANSFER', 'Transfer stock between locations'),
(1, 0, 'SUPPLY_CHAIN_STOCK_ADJUST', 'Adjust stock levels'),
(1, 0, 'SUPPLY_CHAIN_RAW_MATERIAL_VIEW', 'View raw materials'),
(1, 0, 'SUPPLY_CHAIN_RAW_MATERIAL_CREATE', 'Create raw material records'),
(1, 0, 'SUPPLY_CHAIN_RAW_MATERIAL_EDIT', 'Edit raw material records'),
(1, 0, 'SUPPLY_CHAIN_RAW_MATERIAL_DELETE', 'Delete raw material records'),
(1, 0, 'SUPPLY_CHAIN_RAW_MATERIAL_MANAGE', 'Full raw material management'),
(1, 0, 'SUPPLY_CHAIN_QUALITY_CONTROL_VIEW', 'View quality control records'),
(1, 0, 'SUPPLY_CHAIN_QUALITY_CONTROL_CREATE', 'Create quality control records'),
(1, 0, 'SUPPLY_CHAIN_QUALITY_CONTROL_EDIT', 'Edit quality control records'),
(1, 0, 'SUPPLY_CHAIN_QUALITY_CONTROL_APPROVE', 'Approve quality control results'),
(1, 0, 'SUPPLY_CHAIN_WEIGHBRIDGE_VIEW', 'View weighbridge records'),
(1, 0, 'SUPPLY_CHAIN_WEIGHBRIDGE_CREATE', 'Create weighbridge records'),
(1, 0, 'SUPPLY_CHAIN_WEIGHBRIDGE_EDIT', 'Edit weighbridge records'),
(1, 0, 'SUPPLY_CHAIN_GATE_SECURITY_VIEW', 'View gate security records'),
(1, 0, 'SUPPLY_CHAIN_GATE_SECURITY_CREATE', 'Create gate security records'),
(1, 0, 'SUPPLY_CHAIN_GATE_SECURITY_EDIT', 'Edit gate security records'),
(1, 0, 'SUPPLY_CHAIN_GATE_SECURITY_APPROVE', 'Approve gate security entries'),
(1, 0, 'SUPPLY_CHAIN_ACCOUNTS_VIEW', 'View Supply Chain accounts'),
(1, 0, 'SUPPLY_CHAIN_ACCOUNTS_EDIT', 'Edit Supply Chain accounts'),
(1, 0, 'SUPPLY_CHAIN_END_OF_DAY_VIEW', 'View end of day reports'),
(1, 0, 'SUPPLY_CHAIN_END_OF_DAY_PROCESS', 'Process end of day'),
(1, 0, 'SUPPLY_CHAIN_END_OF_DAY_APPROVE', 'Approve end of day processing'),
(1, 0, 'SUPPLY_CHAIN_REPORTS_VIEW', 'View Supply Chain reports'),
(1, 0, 'SUPPLY_CHAIN_REPORTS_EXPORT', 'Export Supply Chain reports'),
(1, 0, 'SUPPLY_CHAIN_LOG_HISTORY_VIEW', 'View Supply Chain log history');

-- ============================================
-- OPERATIONS MODULE (module_id: 2)
-- ============================================
INSERT IGNORE INTO permissions (module_id, store_id, name, description) VALUES
(2, 0, 'OPERATIONS_DASHBOARD_VIEW', 'View Operations dashboard'),
(2, 0, 'OPERATIONS_PRODUCTION_VIEW', 'View production records'),
(2, 0, 'OPERATIONS_PRODUCTION_CREATE', 'Create production records'),
(2, 0, 'OPERATIONS_PRODUCTION_EDIT', 'Edit production records'),
(2, 0, 'OPERATIONS_PRODUCTION_DELETE', 'Delete production records'),
(2, 0, 'OPERATIONS_PRODUCTION_ORDER_VIEW', 'View production orders'),
(2, 0, 'OPERATIONS_PRODUCTION_ORDER_CREATE', 'Create production orders'),
(2, 0, 'OPERATIONS_PRODUCTION_ORDER_EDIT', 'Edit production orders'),
(2, 0, 'OPERATIONS_PRODUCTION_ORDER_APPROVE', 'Approve production orders'),
(2, 0, 'OPERATIONS_PRODUCTION_FLOW_VIEW', 'View production flow'),
(2, 0, 'OPERATIONS_PRODUCTION_FLOW_EDIT', 'Edit production flow'),
(2, 0, 'OPERATIONS_WIP_TRACKING_VIEW', 'View work in progress tracking'),
(2, 0, 'OPERATIONS_WIP_TRACKING_EDIT', 'Edit work in progress tracking'),
(2, 0, 'OPERATIONS_JOB_SCHEDULING_VIEW', 'View job scheduling'),
(2, 0, 'OPERATIONS_JOB_SCHEDULING_EDIT', 'Edit job scheduling'),
(2, 0, 'OPERATIONS_RESCHEDULE_ORDERS', 'Reschedule production orders'),
(2, 0, 'OPERATIONS_QC_VIEW', 'View quality control'),
(2, 0, 'OPERATIONS_QC_INSPECTION_CREATE', 'Create QC inspections'),
(2, 0, 'OPERATIONS_QC_INSPECTION_EDIT', 'Edit QC inspections'),
(2, 0, 'OPERATIONS_QC_RAW_MATERIALS_VIEW', 'View raw materials QC'),
(2, 0, 'OPERATIONS_QC_IN_PROCESS_VIEW', 'View in-process QC'),
(2, 0, 'OPERATIONS_QC_FINISHED_GOODS_VIEW', 'View finished goods QC'),
(2, 0, 'OPERATIONS_QC_DEFECT_LOGGING', 'Log defects'),
(2, 0, 'OPERATIONS_QC_ROOT_CAUSE_ANALYSIS', 'Perform root cause analysis'),
(2, 0, 'OPERATIONS_QC_REWORK_SCRAPPING', 'Manage rework and scrapping'),
(2, 0, 'OPERATIONS_QC_REPORTS_VIEW', 'View QC reports'),
(2, 0, 'OPERATIONS_QC_REPORTS_EXPORT', 'Export QC reports'),
(2, 0, 'OPERATIONS_BOM_VIEW', 'View Bill of Materials'),
(2, 0, 'OPERATIONS_BOM_CREATE', 'Create Bill of Materials'),
(2, 0, 'OPERATIONS_BOM_EDIT', 'Edit Bill of Materials'),
(2, 0, 'OPERATIONS_BOM_DELETE', 'Delete Bill of Materials'),
(2, 0, 'OPERATIONS_BOM_VERSION_CONTROL', 'Manage BOM versions'),
(2, 0, 'OPERATIONS_BOM_APPROVAL_WORKFLOW', 'Approve BOM changes'),
(2, 0, 'OPERATIONS_BOM_CONSUMPTION_TRACKING', 'Track BOM consumption'),
(2, 0, 'OPERATIONS_BOM_COMPLIANCE_REPORTS', 'View BOM compliance reports'),
(2, 0, 'OPERATIONS_STOCK_VIEW', 'View Operations stock'),
(2, 0, 'OPERATIONS_STOCK_CREATE', 'Create Operations stock records'),
(2, 0, 'OPERATIONS_STOCK_EDIT', 'Edit Operations stock records'),
(2, 0, 'OPERATIONS_FINISHED_GOODS_TRACKING', 'Track finished goods'),
(2, 0, 'OPERATIONS_STOCK_COUNTING', 'Perform stock counting'),
(2, 0, 'OPERATIONS_STOCK_VARIANCE_REPORTS', 'View stock variance reports'),
(2, 0, 'OPERATIONS_MRP_VIEW', 'View MRP planning'),
(2, 0, 'OPERATIONS_MRP_DEMAND_FORECASTING', 'Perform demand forecasting'),
(2, 0, 'OPERATIONS_MRP_PLANNED_VS_ACTUAL', 'View planned vs actual'),
(2, 0, 'OPERATIONS_MRP_SHORTAGE_ALERTS', 'View shortage alerts'),
(2, 0, 'OPERATIONS_MRP_REQUIREMENTS_CALCULATOR', 'Use requirements calculator'),
(2, 0, 'OPERATIONS_MAINTENANCE_VIEW', 'View maintenance records'),
(2, 0, 'OPERATIONS_MAINTENANCE_PREVENTIVE_CREATE', 'Create preventive maintenance'),
(2, 0, 'OPERATIONS_MAINTENANCE_PREVENTIVE_EDIT', 'Edit preventive maintenance'),
(2, 0, 'OPERATIONS_MAINTENANCE_SCHEDULING', 'Schedule maintenance'),
(2, 0, 'OPERATIONS_MAINTENANCE_RECORDS_VIEW', 'View maintenance records'),
(2, 0, 'OPERATIONS_MAINTENANCE_DOWNTIME_TRACKING', 'Track downtime'),
(2, 0, 'OPERATIONS_MAINTENANCE_BREAKDOWN_VIEW', 'View machine breakdowns'),
(2, 0, 'OPERATIONS_MAINTENANCE_DOWNTIME_ANALYSIS', 'Analyze downtime causes'),
(2, 0, 'OPERATIONS_MAINTENANCE_REQUEST_RAISE', 'Raise maintenance requests'),
(2, 0, 'OPERATIONS_MAINTENANCE_REQUEST_APPROVE', 'Approve maintenance requests'),
(2, 0, 'OPERATIONS_MAINTENANCE_REQUEST_ASSIGN', 'Assign technicians'),
(2, 0, 'OPERATIONS_MAINTENANCE_STATUS_MONITOR', 'Monitor maintenance status'),
(2, 0, 'OPERATIONS_WAREHOUSE_LAYOUT_VIEW', 'View warehouse layout'),
(2, 0, 'OPERATIONS_WAREHOUSE_LAYOUT_EDIT', 'Edit warehouse layout'),
(2, 0, 'OPERATIONS_WAREHOUSE_LOCATION_MANAGE', 'Manage warehouse locations'),
(2, 0, 'OPERATIONS_WAREHOUSE_RECEIVING_VIEW', 'View warehouse receiving'),
(2, 0, 'OPERATIONS_WAREHOUSE_INVENTORY_MOVEMENTS', 'View inventory movements'),
(2, 0, 'OPERATIONS_PROJECT_VIEW', 'View projects'),
(2, 0, 'OPERATIONS_PROJECT_CREATE', 'Create projects'),
(2, 0, 'OPERATIONS_PROJECT_EDIT', 'Edit projects'),
(2, 0, 'OPERATIONS_PROJECT_ASSIGN', 'Assign projects'),
(2, 0, 'OPERATIONS_PROJECT_MILESTONES_DEFINE', 'Define project milestones'),
(2, 0, 'OPERATIONS_PROJECT_EXECUTION_TRACKING', 'Track project execution'),
(2, 0, 'OPERATIONS_PROJECT_TASKS_DEADLINES', 'Manage tasks and deadlines'),
(2, 0, 'OPERATIONS_PROJECT_RESOURCE_ALLOCATION', 'Allocate project resources'),
(2, 0, 'OPERATIONS_PROJECT_PERFORMANCE_REPORTS', 'View project performance reports'),
(2, 0, 'OPERATIONS_REPORTS_VIEW', 'View Operations reports'),
(2, 0, 'OPERATIONS_REPORTS_PRODUCTION_PERFORMANCE', 'View production performance reports'),
(2, 0, 'OPERATIONS_REPORTS_QC', 'View QC reports'),
(2, 0, 'OPERATIONS_REPORTS_MAINTENANCE', 'View maintenance reports'),
(2, 0, 'OPERATIONS_REPORTS_BOM_COMPLIANCE', 'View BOM compliance reports'),
(2, 0, 'OPERATIONS_REPORTS_MRP_FORECAST', 'View MRP forecast reports'),
(2, 0, 'OPERATIONS_REPORTS_PROJECT_STATUS', 'View project status reports'),
(2, 0, 'OPERATIONS_REPORTS_EXPORT', 'Export Operations reports');

-- ============================================
-- ACCOUNTS MODULE (module_id: 4)
-- ============================================
INSERT IGNORE INTO permissions (module_id, store_id, name, description) VALUES
(4, 0, 'ACCOUNTS_DASHBOARD_VIEW', 'View Accounts dashboard'),
(4, 0, 'ACCOUNTS_CHART_OF_ACCOUNTS_VIEW', 'View chart of accounts'),
(4, 0, 'ACCOUNTS_CHART_OF_ACCOUNTS_CREATE', 'Create chart of accounts'),
(4, 0, 'ACCOUNTS_CHART_OF_ACCOUNTS_EDIT', 'Edit chart of accounts'),
(4, 0, 'ACCOUNTS_CHART_OF_ACCOUNTS_DELETE', 'Delete chart of accounts'),
(4, 0, 'ACCOUNTS_ACCOUNT_TYPES_MANAGE', 'Manage account types'),
(4, 0, 'ACCOUNTS_ACCOUNT_CATEGORIES_MANAGE', 'Manage account categories'),
(4, 0, 'ACCOUNTS_ACCOUNT_GROUPS_MANAGE', 'Manage account groups'),
(4, 0, 'ACCOUNTS_GENERAL_LEDGER_VIEW', 'View general ledger'),
(4, 0, 'ACCOUNTS_GENERAL_LEDGER_MASTER_RECORDS', 'Manage GL master records'),
(4, 0, 'ACCOUNTS_JOURNAL_ENTRY_VIEW', 'View journal entries'),
(4, 0, 'ACCOUNTS_JOURNAL_ENTRY_CREATE', 'Create journal entries'),
(4, 0, 'ACCOUNTS_JOURNAL_ENTRY_EDIT', 'Edit journal entries'),
(4, 0, 'ACCOUNTS_JOURNAL_ENTRY_APPROVE', 'Approve journal entries'),
(4, 0, 'ACCOUNTS_JOURNAL_ENTRY_DELETE', 'Delete journal entries'),
(4, 0, 'ACCOUNTS_TRIAL_BALANCE_VIEW', 'View trial balance'),
(4, 0, 'ACCOUNTS_LEDGER_REPORTS_VIEW', 'View ledger reports'),
(4, 0, 'ACCOUNTS_COST_CENTERS_MANAGE', 'Manage cost centers'),
(4, 0, 'ACCOUNTS_DEPARTMENTS_MANAGE', 'Manage departments'),
(4, 0, 'ACCOUNTS_PROJECTS_MANAGE', 'Manage projects'),
(4, 0, 'ACCOUNTS_BRANCHES_MANAGE', 'Manage branches'),
(4, 0, 'ACCOUNTS_COST_ALLOCATIONS_MANAGE', 'Manage cost allocations'),
(4, 0, 'ACCOUNTS_INTER_COMPANY_ELIMINATIONS', 'Manage inter-company eliminations'),
(4, 0, 'ACCOUNTS_GROUP_CONSOLIDATED_REPORTING', 'View group consolidated reports'),
(4, 0, 'ACCOUNTS_PAYABLE_VIEW', 'View accounts payable'),
(4, 0, 'ACCOUNTS_PAYABLE_DASHBOARD_VIEW', 'View AP dashboard'),
(4, 0, 'ACCOUNTS_PAYABLE_VENDOR_INVOICE_CREATE', 'Create vendor invoices'),
(4, 0, 'ACCOUNTS_PAYABLE_VENDOR_INVOICE_EDIT', 'Edit vendor invoices'),
(4, 0, 'ACCOUNTS_PAYABLE_VENDOR_INVOICE_APPROVE', 'Approve vendor invoices'),
(4, 0, 'ACCOUNTS_PAYABLE_SCHEDULED_PAYMENTS_VIEW', 'View scheduled payments'),
(4, 0, 'ACCOUNTS_PAYABLE_VENDOR_AGING_REPORTS', 'View vendor aging reports'),
(4, 0, 'ACCOUNTS_PAYABLE_VENDOR_BILLS_VIEW', 'View vendor bills'),
(4, 0, 'ACCOUNTS_PAYABLE_CREDIT_NOTES_CREATE', 'Create AP credit notes'),
(4, 0, 'ACCOUNTS_PAYABLE_PAYMENT_RUNS_CREATE', 'Create payment runs'),
(4, 0, 'ACCOUNTS_PAYABLE_PAYMENT_RUNS_APPROVE', 'Approve payment runs'),
(4, 0, 'ACCOUNTS_PAYABLE_VENDOR_STATEMENTS_VIEW', 'View vendor statements'),
(4, 0, 'ACCOUNTS_PAYABLE_PAYMENT_REQUESTS_CREATE', 'Create payment requests'),
(4, 0, 'ACCOUNTS_PAYABLE_PAYMENT_REQUESTS_APPROVE', 'Approve payment requests'),
(4, 0, 'ACCOUNTS_PAYABLE_SUPPLIER_BANK_ACCOUNTS_MANAGE', 'Manage supplier bank accounts'),
(4, 0, 'ACCOUNTS_PAYABLE_ALLOCATIONS_MANAGE', 'Manage AP allocations'),
(4, 0, 'ACCOUNTS_PAYABLE_SUPPLIERS_MANAGE', 'Manage suppliers'),
(4, 0, 'ACCOUNTS_PAYABLE_QC_COMPLETED_POS_VIEW', 'View QC completed POs'),
(4, 0, 'ACCOUNTS_PAYABLE_AGING_BILLS_VIEW', 'View aging bills'),
(4, 0, 'ACCOUNTS_RECEIVABLE_VIEW', 'View accounts receivable'),
(4, 0, 'ACCOUNTS_RECEIVABLE_DASHBOARD_VIEW', 'View AR dashboard'),
(4, 0, 'ACCOUNTS_RECEIVABLE_CUSTOMER_ACCOUNTS_MANAGE', 'Manage customer accounts'),
(4, 0, 'ACCOUNTS_RECEIVABLE_INVOICE_CREATE', 'Create customer invoices'),
(4, 0, 'ACCOUNTS_RECEIVABLE_INVOICE_EDIT', 'Edit customer invoices'),
(4, 0, 'ACCOUNTS_RECEIVABLE_INVOICE_APPROVE', 'Approve customer invoices'),
(4, 0, 'ACCOUNTS_RECEIVABLE_PAYMENT_MANAGE', 'Manage customer payments'),
(4, 0, 'ACCOUNTS_RECEIVABLE_DEBT_CREDIT_MANAGE', 'Manage debt and credit'),
(4, 0, 'ACCOUNTS_RECEIVABLE_PAYMENT_REMINDERS', 'Send payment reminders'),
(4, 0, 'ACCOUNTS_RECEIVABLE_LEDGER_JOURNAL_ENTRIES', 'View AR ledger journal entries'),
(4, 0, 'ACCOUNTS_RECEIVABLE_REPORTS_ANALYTICS', 'View AR reports and analytics'),
(4, 0, 'ACCOUNTS_RECEIVABLE_INTEGRATION_SETTINGS', 'Manage AR integration settings'),
(4, 0, 'ACCOUNTS_BUDGET_VIEW', 'View budgets'),
(4, 0, 'ACCOUNTS_BUDGET_SETUP', 'Setup budgets'),
(4, 0, 'ACCOUNTS_BUDGET_FORECASTING', 'Perform budget forecasting'),
(4, 0, 'ACCOUNTS_REVENUE_FORECASTING', 'Perform revenue forecasting'),
(4, 0, 'ACCOUNTS_EXPENSE_FORECASTING', 'Perform expense forecasting'),
(4, 0, 'ACCOUNTS_CASH_FLOW_VIEW', 'View cash flow'),
(4, 0, 'ACCOUNTS_CASH_FLOW_MANAGE', 'Manage cash flow'),
(4, 0, 'ACCOUNTS_CASH_INFLOW_OUTFLOW_VIEW', 'View cash inflow/outflow'),
(4, 0, 'ACCOUNTS_DAILY_CASH_POSITION_VIEW', 'View daily cash position'),
(4, 0, 'ACCOUNTS_CASH_FLOW_FORECASTS', 'View cash flow forecasts'),
(4, 0, 'ACCOUNTS_LIQUIDITY_ALERTS', 'View liquidity alerts'),
(4, 0, 'ACCOUNTS_BANK_RECONCILIATION_VIEW', 'View bank reconciliation'),
(4, 0, 'ACCOUNTS_BANK_RECONCILIATION_PROCESS', 'Process bank reconciliation'),
(4, 0, 'ACCOUNTS_BANK_STATEMENT_IMPORT', 'Import bank statements'),
(4, 0, 'ACCOUNTS_BANK_RECONCILIATION_AUTOMATED', 'Use automated bank reconciliation'),
(4, 0, 'ACCOUNTS_UNRECONCILED_TRANSACTIONS_VIEW', 'View unreconciled transactions'),
(4, 0, 'ACCOUNTS_BANK_RECONCILIATION_VARIANCE_REPORTS', 'View bank reconciliation variance reports'),
(4, 0, 'ACCOUNTS_FIXED_ASSETS_VIEW', 'View fixed assets'),
(4, 0, 'ACCOUNTS_FIXED_ASSETS_MANAGE', 'Manage fixed assets'),
(4, 0, 'ACCOUNTS_ASSET_REGISTER_VIEW', 'View asset register'),
(4, 0, 'ACCOUNTS_ASSET_ACQUISITION_DISPOSAL', 'Manage asset acquisition and disposal'),
(4, 0, 'ACCOUNTS_ASSET_DEPRECIATION', 'Manage asset depreciation'),
(4, 0, 'ACCOUNTS_ASSET_VALUATION_REPORTS', 'View asset valuation reports'),
(4, 0, 'ACCOUNTS_WAREHOUSE_VIEW', 'View Accounts warehouse'),
(4, 0, 'ACCOUNTS_WAREHOUSE_MANAGE', 'Manage Accounts warehouse'),
(4, 0, 'ACCOUNTS_WAREHOUSE_REGISTER', 'View warehouse register'),
(4, 0, 'ACCOUNTS_WAREHOUSE_UTILIZATION_REPORTS', 'View warehouse utilization reports'),
(4, 0, 'ACCOUNTS_INVENTORY_VIEW', 'View Accounts inventory'),
(4, 0, 'ACCOUNTS_INVENTORY_MANAGE', 'Manage Accounts inventory'),
(4, 0, 'ACCOUNTS_INVENTORY_VALUATION', 'View inventory valuation'),
(4, 0, 'ACCOUNTS_INVENTORY_REPORTS', 'View inventory reports'),
(4, 0, 'ACCOUNTS_PHYSICAL_STOCK_VIEW', 'View physical stock'),
(4, 0, 'ACCOUNTS_PHYSICAL_STOCK_COUNT', 'Perform physical stock count'),
(4, 0, 'ACCOUNTS_PHYSICAL_STOCK_ADJUST', 'Adjust physical stock'),
(4, 0, 'ACCOUNTS_REPORTS_VIEW', 'View Accounts reports'),
(4, 0, 'ACCOUNTS_REPORTS_FINANCIAL', 'View financial reports'),
(4, 0, 'ACCOUNTS_REPORTS_EXPORT', 'Export Accounts reports'),
(4, 0, 'ACCOUNTS_AUDIT_LOGS_VIEW', 'View Accounts audit logs');

-- ============================================
-- HR MODULE (module_id: 6)
-- ============================================
INSERT IGNORE INTO permissions (module_id, store_id, name, description) VALUES
(6, 0, 'HR_DASHBOARD_VIEW', 'View HR dashboard'),
(6, 0, 'HR_EMPLOYEE_VIEW', 'View employees'),
(6, 0, 'HR_EMPLOYEE_CREATE', 'Create employees'),
(6, 0, 'HR_EMPLOYEE_EDIT', 'Edit employees'),
(6, 0, 'HR_EMPLOYEE_DELETE', 'Delete employees'),
(6, 0, 'HR_EMPLOYEE_MANAGE', 'Full employee management'),
(6, 0, 'HR_ATTENDANCE_VIEW', 'View attendance'),
(6, 0, 'HR_ATTENDANCE_CREATE', 'Create attendance records'),
(6, 0, 'HR_ATTENDANCE_EDIT', 'Edit attendance records'),
(6, 0, 'HR_ATTENDANCE_MANAGE', 'Full attendance management'),
(6, 0, 'HR_PAYROLL_VIEW', 'View payroll'),
(6, 0, 'HR_PAYROLL_CREATE', 'Create payroll records'),
(6, 0, 'HR_PAYROLL_EDIT', 'Edit payroll records'),
(6, 0, 'HR_PAYROLL_PROCESS', 'Process payroll'),
(6, 0, 'HR_PAYROLL_APPROVE', 'Approve payroll'),
(6, 0, 'HR_PERFORMANCE_VIEW', 'View performance records'),
(6, 0, 'HR_PERFORMANCE_CREATE', 'Create performance records'),
(6, 0, 'HR_PERFORMANCE_EDIT', 'Edit performance records'),
(6, 0, 'HR_PERFORMANCE_APPROVE', 'Approve performance reviews'),
(6, 0, 'HR_PERFORMANCE_REPORTS', 'View performance reports'),
(6, 0, 'HR_RECRUITMENT_VIEW', 'View recruitment'),
(6, 0, 'HR_RECRUITMENT_CREATE', 'Create recruitment records'),
(6, 0, 'HR_RECRUITMENT_EDIT', 'Edit recruitment records'),
(6, 0, 'HR_RECRUITMENT_APPROVE', 'Approve recruitment'),
(6, 0, 'HR_LEAVE_VIEW', 'View leave records'),
(6, 0, 'HR_LEAVE_CREATE', 'Create leave requests'),
(6, 0, 'HR_LEAVE_EDIT', 'Edit leave records'),
(6, 0, 'HR_LEAVE_APPROVE', 'Approve leave requests'),
(6, 0, 'HR_LEAVE_MANAGE', 'Full leave management'),
(6, 0, 'HR_REPORTS_VIEW', 'View HR reports'),
(6, 0, 'HR_REPORTS_EXPORT', 'Export HR reports');

-- ============================================
-- CRM MODULE (module_id: 8)
-- ============================================
INSERT IGNORE INTO permissions (module_id, store_id, name, description) VALUES
(8, 0, 'CRM_DASHBOARD_VIEW', 'View CRM dashboard'),
(8, 0, 'CRM_CUSTOMER_VIEW', 'View customers'),
(8, 0, 'CRM_CUSTOMER_CREATE', 'Create customers'),
(8, 0, 'CRM_CUSTOMER_EDIT', 'Edit customers'),
(8, 0, 'CRM_CUSTOMER_DELETE', 'Delete customers'),
(8, 0, 'CRM_CUSTOMER_MANAGE', 'Full customer management'),
(8, 0, 'CRM_ORDER_VIEW', 'View orders'),
(8, 0, 'CRM_ORDER_CREATE', 'Create orders'),
(8, 0, 'CRM_ORDER_EDIT', 'Edit orders'),
(8, 0, 'CRM_ORDER_APPROVE', 'Approve orders'),
(8, 0, 'CRM_ORDER_DELETE', 'Delete orders'),
(8, 0, 'CRM_CONTRACT_VIEW', 'View contracts and agreements'),
(8, 0, 'CRM_CONTRACT_CREATE', 'Create contracts and agreements'),
(8, 0, 'CRM_CONTRACT_EDIT', 'Edit contracts and agreements'),
(8, 0, 'CRM_CONTRACT_APPROVE', 'Approve contracts and agreements'),
(8, 0, 'CRM_CONTRACT_MANAGE', 'Full contract management'),
(8, 0, 'CRM_CREDIT_VIEW', 'View credit management'),
(8, 0, 'CRM_CREDIT_MANAGE', 'Manage credit'),
(8, 0, 'CRM_CREDIT_APPROVE', 'Approve credit'),
(8, 0, 'CRM_CREDIT_LIMIT_EDIT', 'Edit credit limits'),
(8, 0, 'CRM_REBATE_VIEW', 'View rebates and incentives'),
(8, 0, 'CRM_REBATE_CREATE', 'Create rebates and incentives'),
(8, 0, 'CRM_REBATE_EDIT', 'Edit rebates and incentives'),
(8, 0, 'CRM_REBATE_APPROVE', 'Approve rebates and incentives'),
(8, 0, 'CRM_REBATE_MANAGE', 'Full rebate management'),
(8, 0, 'CRM_PRODUCT_PRICING_VIEW', 'View product pricing'),
(8, 0, 'CRM_PRODUCT_PRICING_EDIT', 'Edit product pricing'),
(8, 0, 'CRM_PRODUCT_PRICING_MANAGE', 'Full product pricing management'),
(8, 0, 'CRM_PERFORMANCE_VIEW', 'View performance and loyalty'),
(8, 0, 'CRM_PERFORMANCE_REPORTS', 'View performance reports'),
(8, 0, 'CRM_ANALYTICS_VIEW', 'View analytics and BI'),
(8, 0, 'CRM_ANALYTICS_EXPORT', 'Export analytics'),
(8, 0, 'CRM_COMMUNICATION_VIEW', 'View communication'),
(8, 0, 'CRM_COMMUNICATION_SEND', 'Send communications'),
(8, 0, 'CRM_REPORTS_VIEW', 'View CRM reports'),
(8, 0, 'CRM_REPORTS_EXPORT', 'Export CRM reports');

-- ============================================
-- MD (MASTER DATA) MODULE (module_id: 3)
-- ============================================
INSERT IGNORE INTO permissions (module_id, store_id, name, description) VALUES
(3, 0, 'MD_DASHBOARD_VIEW', 'View MD dashboard'),
(3, 0, 'MD_EXECUTIVE_DASHBOARD_VIEW', 'View executive dashboard'),
(3, 0, 'MD_SUPPLY_CHAIN_VIEW', 'View Supply Chain overview'),
(3, 0, 'MD_PROCUREMENT_VIEW', 'View procurement overview'),
(3, 0, 'MD_SUPPLIER_PROFILES_VIEW', 'View supplier profiles'),
(3, 0, 'MD_SUPPLIER_PERFORMANCE_VIEW', 'View supplier performance'),
(3, 0, 'MD_STOCK_LEVELS_VIEW', 'View stock levels'),
(3, 0, 'MD_RAW_MATERIALS_VIEW', 'View raw materials overview'),
(3, 0, 'MD_REPLENISHMENT_ALERTS_VIEW', 'View replenishment alerts'),
(3, 0, 'MD_MASTER_DATA_VIEW', 'View master data'),
(3, 0, 'MD_MASTER_DATA_CREATE', 'Create master data'),
(3, 0, 'MD_MASTER_DATA_EDIT', 'Edit master data'),
(3, 0, 'MD_MASTER_DATA_DELETE', 'Delete master data'),
(3, 0, 'MD_MASTER_DATA_MANAGE', 'Full master data management'),
(3, 0, 'MD_PRODUCT_CATALOG_VIEW', 'View product catalog'),
(3, 0, 'MD_PRODUCT_CATALOG_CREATE', 'Create product catalog entries'),
(3, 0, 'MD_PRODUCT_CATALOG_EDIT', 'Edit product catalog entries'),
(3, 0, 'MD_PRODUCT_CATALOG_DELETE', 'Delete product catalog entries'),
(3, 0, 'MD_PRODUCT_CATALOG_MANAGE', 'Full product catalog management'),
(3, 0, 'MD_PRICING_VIEW', 'View pricing'),
(3, 0, 'MD_PRICING_EDIT', 'Edit pricing'),
(3, 0, 'MD_PRICING_MANAGE', 'Full pricing management'),
(3, 0, 'MD_CATEGORIES_VIEW', 'View categories'),
(3, 0, 'MD_CATEGORIES_CREATE', 'Create categories'),
(3, 0, 'MD_CATEGORIES_EDIT', 'Edit categories'),
(3, 0, 'MD_CATEGORIES_DELETE', 'Delete categories'),
(3, 0, 'MD_CATEGORIES_MANAGE', 'Full category management'),
(3, 0, 'MD_FINANCIAL_REPORTS_VIEW', 'View financial reports'),
(3, 0, 'MD_FINANCIAL_REPORTS_EXPORT', 'Export financial reports');

-- ============================================
-- AUDIT MODULE (module_id: 5)
-- ============================================
INSERT IGNORE INTO permissions (module_id, store_id, name, description) VALUES
(5, 0, 'AUDIT_DASHBOARD_VIEW', 'View Audit dashboard'),
(5, 0, 'AUDIT_FINANCIAL_VIEW', 'View financial audit'),
(5, 0, 'AUDIT_FINANCIAL_EXPORT', 'Export financial audit'),
(5, 0, 'AUDIT_SUPPLY_CHAIN_VIEW', 'View Supply Chain audit'),
(5, 0, 'AUDIT_SUPPLY_CHAIN_EXPORT', 'Export Supply Chain audit'),
(5, 0, 'AUDIT_OPERATIONS_VIEW', 'View Operations audit'),
(5, 0, 'AUDIT_OPERATIONS_EXPORT', 'Export Operations audit'),
(5, 0, 'AUDIT_HR_VIEW', 'View HR audit'),
(5, 0, 'AUDIT_HR_EXPORT', 'Export HR audit'),
(5, 0, 'AUDIT_CUSTOMER_SALES_VIEW', 'View customer and sales audit'),
(5, 0, 'AUDIT_CUSTOMER_SALES_EXPORT', 'Export customer and sales audit'),
(5, 0, 'AUDIT_DOCUMENT_COMPLIANCE_VIEW', 'View document and compliance audit'),
(5, 0, 'AUDIT_DOCUMENT_COMPLIANCE_EXPORT', 'Export document and compliance audit'),
(5, 0, 'AUDIT_USER_ACCESS_ROLES_VIEW', 'View user access and roles audit'),
(5, 0, 'AUDIT_USER_ACCESS_ROLES_EXPORT', 'Export user access and roles audit'),
(5, 0, 'AUDIT_TRANSACTIONS_VIEW', 'View transaction audits'),
(5, 0, 'AUDIT_TRANSACTIONS_EXPORT', 'Export transaction audits'),
(5, 0, 'AUDIT_COMPLIANCE_REPORTS_VIEW', 'View compliance reports'),
(5, 0, 'AUDIT_COMPLIANCE_REPORTS_EXPORT', 'Export compliance reports'),
(5, 0, 'AUDIT_ALERTS_VIEW', 'View audit alerts'),
(5, 0, 'AUDIT_ALERTS_MANAGE', 'Manage audit alerts'),
(5, 0, 'AUDIT_SYSTEM_TRAIL_VIEW', 'View system audit trail'),
(5, 0, 'AUDIT_SYSTEM_TRAIL_EXPORT', 'Export system audit trail');

-- ============================================
-- WAREHOUSE MODULE
-- ============================================
-- Note: Warehouse module may not have a specific module_id, using 0 for now
-- Adjust module_id if warehouse has its own module
INSERT IGNORE INTO permissions (module_id, store_id, name, description) VALUES
(0, 0, 'WAREHOUSE_DASHBOARD_VIEW', 'View Warehouse dashboard'),
(0, 0, 'WAREHOUSE_STOCK_VIEW', 'View warehouse stock'),
(0, 0, 'WAREHOUSE_STOCK_CREATE', 'Create warehouse stock records'),
(0, 0, 'WAREHOUSE_STOCK_EDIT', 'Edit warehouse stock records'),
(0, 0, 'WAREHOUSE_STOCK_ADJUST', 'Adjust warehouse stock'),
(0, 0, 'WAREHOUSE_TRANSFER_VIEW', 'View warehouse transfers'),
(0, 0, 'WAREHOUSE_TRANSFER_CREATE', 'Create warehouse transfers'),
(0, 0, 'WAREHOUSE_TRANSFER_APPROVE', 'Approve warehouse transfers'),
(0, 0, 'WAREHOUSE_RECEIPT_VIEW', 'View warehouse receipts'),
(0, 0, 'WAREHOUSE_RECEIPT_CREATE', 'Create warehouse receipts'),
(0, 0, 'WAREHOUSE_RECEIPT_EDIT', 'Edit warehouse receipts'),
(0, 0, 'WAREHOUSE_REPORTS_VIEW', 'View warehouse reports'),
(0, 0, 'WAREHOUSE_REPORTS_EXPORT', 'Export warehouse reports');

-- ============================================
-- APPROVAL MODULE
-- ============================================
-- Note: Approval module may not have a specific module_id, using 0 for now
-- Adjust module_id if approval has its own module
INSERT IGNORE INTO permissions (module_id, store_id, name, description) VALUES
(0, 0, 'APPROVAL_WORKFLOW_VIEW', 'View approval workflows'),
(0, 0, 'APPROVAL_WORKFLOW_CREATE', 'Create approval workflows'),
(0, 0, 'APPROVAL_WORKFLOW_EDIT', 'Edit approval workflows'),
(0, 0, 'APPROVAL_WORKFLOW_DELETE', 'Delete approval workflows'),
(0, 0, 'APPROVAL_WORKFLOW_MANAGE', 'Full approval workflow management'),
(0, 0, 'APPROVAL_PENDING_VIEW', 'View pending approvals'),
(0, 0, 'APPROVAL_PENDING_APPROVE', 'Approve pending requests'),
(0, 0, 'APPROVAL_PENDING_REJECT', 'Reject pending requests'),
(0, 0, 'APPROVAL_HISTORY_VIEW', 'View approval history'),
(0, 0, 'APPROVAL_HISTORY_EXPORT', 'Export approval history');

-- ============================================
-- DMS MODULE (Document Management)
-- ============================================
-- Note: DMS has public access for most features
-- Only approval and version control require permissions (department heads only)
-- Module ID may need to be adjusted based on your DMS module_id
INSERT IGNORE INTO permissions (module_id, store_id, name, description) VALUES
(0, 0, 'DMS_DOCUMENT_APPROVE', 'Approve/reject documents (Department Heads only)'),
(0, 0, 'DMS_VERSION_CONTROL_MANAGE', 'Manage document versions (Department Heads only)');

-- ============================================
-- COMMON PERMISSIONS (Cross-Module)
-- ============================================
INSERT IGNORE INTO permissions (module_id, store_id, name, description) VALUES
(0, 0, 'MANAGE_USERS', 'Create, edit, delete users (already exists)'),
(0, 0, 'MANAGE_ROLES', 'Create, edit, delete roles'),
(0, 0, 'MANAGE_PERMISSIONS', 'Create, edit, delete permissions'),
(0, 0, 'VIEW_AUDIT_LOGS', 'View system audit logs'),
(0, 0, 'EXPORT_DATA', 'Export data from any module'),
(0, 0, 'IMPORT_DATA', 'Import data to any module');

-- ============================================
-- NOTES
-- ============================================
-- 1. Chat Module: No permissions required - all authenticated users have full access
-- 2. DMS Module: Most features are public (no permissions), only approval and version control require department head status
-- 3. Module IDs may need adjustment based on your actual module setup
-- 4. Store ID 0 means global permissions - can be overridden with store-specific permissions later
-- 5. All permissions use INSERT IGNORE to prevent duplicates if script is run multiple times



