USE fortify_cms;

CREATE TABLE IF NOT EXISTS translations (
  id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  translation_key VARCHAR(190) NOT NULL UNIQUE,
  module VARCHAR(120) NOT NULL DEFAULT 'general',
  ar_value TEXT NOT NULL,
  en_value TEXT NULL,
  created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_translations_module (module)
);

INSERT IGNORE INTO permissions (permission_key, permission_name, module) VALUES
('view_translations','View translations','translations'),
('create_translations','Create translations','translations'),
('edit_translations','Edit translations','translations'),
('delete_translations','Delete translations','translations'),
('view_backups','View backups','backups'),
('create_backups','Create backups','backups'),
('restore_backups','Restore backups','backups'),
('delete_backups','Delete backups','backups'),
('view_system_updates','View system updates','system_updates'),
('apply_system_updates','Apply system updates','system_updates'),
('view_system_routes','View system routes','system_routes');

INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT 1, id FROM permissions WHERE permission_key IN ('view_translations','create_translations','edit_translations','delete_translations','view_backups','create_backups','restore_backups','delete_backups','view_system_updates','apply_system_updates','view_system_routes');

INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT 2, id FROM permissions WHERE permission_key IN ('view_translations','create_translations','edit_translations','view_backups','create_backups','restore_backups','view_system_updates','apply_system_updates','view_system_routes');

INSERT IGNORE INTO role_permissions (role_id, permission_id)
SELECT 3, id FROM permissions WHERE permission_key IN ('view_translations');

INSERT INTO settings (setting_key, setting_value) VALUES
('site_name_ar', 'الحصن التقني لتكنولوجيا المعلومات'),
('company_name_ar', 'الحصن التقني لتكنولوجيا المعلومات'),
('company_name_en', 'Fortify Information Technology'),
('company_description_ar', 'شركة عراقية تقدم حلول تقنية وأنظمة ذكية متكاملة.'),
('company_description_en', 'An Iraqi company delivering integrated technology and smart systems.'),
('default_language', 'ar'),
('timezone', 'Asia/Baghdad'),
('maintenance_mode', '0'),
('site_address_ar', 'العراق'),
('site_address_en', 'Iraq'),
('site_logo_dark', '/assets/fortify-logo.png'),
('og_image', '/assets/fortify-logo.png'),
('admin_logo', '/assets/fortify-logo.png'),
('brand_primary_color', '#080d12'),
('brand_secondary_color', '#39d0d4'),
('brand_accent_color', '#e46f27'),
('brand_font_family', 'Inter, system-ui, sans-serif'),
('meta_title_ar', 'الحصن التقني | Fortify'),
('meta_title_en', 'Fortify Information Technology'),
('meta_description_ar', 'حلول تقنية، طاقة شمسية، كاميرات مراقبة، أنظمة صوتيات، إنذار حريق، أنظمة أمنية، بنية تحتية، وتطوير رقمي.'),
('meta_description_en', 'Technology, solar energy, surveillance cameras, audio, fire alarm, security systems, infrastructure, and digital development.'),
('meta_keywords', 'Fortify, الحصن التقني, IT, security systems, solar energy'),
('robots_indexing', 'index'),
('mail_driver', 'smtp'),
('smtp_host', ''),
('smtp_port', '587'),
('smtp_username', ''),
('smtp_password', ''),
('smtp_encryption', 'tls'),
('mail_from_email', 'info@4tiify.com'),
('mail_from_name', 'Fortify'),
('orders_notify_email', 'info@4tiify.com'),
('facebook_url', ''),
('instagram_url', ''),
('linkedin_url', ''),
('x_url', ''),
('whatsapp_number', ''),
('items_per_page', '20'),
('max_upload_size_mb', '5'),
('allowed_upload_types', 'jpg,jpeg,png,webp,svg'),
('recaptcha_site_key', ''),
('recaptcha_secret_key', '')
ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value);

INSERT INTO translations (translation_key, module, ar_value, en_value) VALUES
('nav.home', 'navigation', 'الرئيسية', 'Home'),
('nav.about', 'navigation', 'من نحن', 'About'),
('nav.services', 'navigation', 'الخدمات', 'Services'),
('nav.systems', 'navigation', 'الأنظمة', 'Systems'),
('nav.work', 'navigation', 'أعمالنا', 'Work'),
('nav.request', 'navigation', 'طلب خدمة', 'Request service'),
('common.save', 'admin', 'حفظ', 'Save'),
('common.edit', 'admin', 'تعديل', 'Edit'),
('common.delete', 'admin', 'حذف', 'Delete'),
('settings.title', 'admin', 'إعدادات الموقع', 'Site settings')
ON DUPLICATE KEY UPDATE ar_value = VALUES(ar_value), en_value = VALUES(en_value), module = VALUES(module);
