-- ============================================================
-- NGO MIS - Seeders
-- Phase 1 | Default Data
-- ============================================================

-- ============================================================
-- ROLES
-- ============================================================
INSERT INTO `roles` (`name`, `slug`, `description`, `is_system`) VALUES
('Super Admin', 'super_admin', 'Full access to all modules', 1),
('Admin', 'admin', 'Administrative access', 1),
('Manager', 'manager', 'Management and reporting access', 1),
('CSR Manager', 'csr_manager', 'CSR company, project and expense access', 1),
('Accountant', 'accountant', 'Donations and expenses access', 1),
('Volunteer', 'volunteer', 'Limited volunteer functions', 1),
('Staff', 'staff', 'Assigned modules only', 1);

-- ============================================================
-- PERMISSIONS
-- ============================================================
INSERT INTO `permissions` (`module`, `action`, `slug`, `description`) VALUES
-- Dashboard
('dashboard', 'view', 'dashboard.view', 'View dashboard'),

-- Users
('users', 'view', 'users.view', 'View users'),
('users', 'create', 'users.create', 'Create users'),
('users', 'edit', 'users.edit', 'Edit users'),
('users', 'delete', 'users.delete', 'Delete users'),
('users', 'manage_permissions', 'users.manage_permissions', 'Manage user permissions'),

-- Departments
('departments', 'view', 'departments.view', 'View departments'),
('departments', 'create', 'departments.create', 'Create departments'),
('departments', 'edit', 'departments.edit', 'Edit departments'),
('departments', 'delete', 'departments.delete', 'Delete departments'),

-- CSR Companies
('csr_companies', 'view', 'csr_companies.view', 'View CSR companies'),
('csr_companies', 'create', 'csr_companies.create', 'Create CSR companies'),
('csr_companies', 'edit', 'csr_companies.edit', 'Edit CSR companies'),
('csr_companies', 'delete', 'csr_companies.delete', 'Delete CSR companies'),

-- Project Categories
('project_categories', 'view', 'project_categories.view', 'View project categories'),
('project_categories', 'create', 'project_categories.create', 'Create project categories'),
('project_categories', 'edit', 'project_categories.edit', 'Edit project categories'),
('project_categories', 'delete', 'project_categories.delete', 'Delete project categories'),

-- Projects
('projects', 'view', 'projects.view', 'View projects'),
('projects', 'create', 'projects.create', 'Create projects'),
('projects', 'edit', 'projects.edit', 'Edit projects'),
('projects', 'delete', 'projects.delete', 'Delete projects'),
('projects', 'approve', 'projects.approve', 'Approve projects'),

-- Project Expenses
('project_expenses', 'view', 'project_expenses.view', 'View project expenses'),
('project_expenses', 'create', 'project_expenses.create', 'Create project expenses'),
('project_expenses', 'edit', 'project_expenses.edit', 'Edit project expenses'),
('project_expenses', 'delete', 'project_expenses.delete', 'Delete project expenses'),
('project_expenses', 'override_budget', 'project_expenses.override_budget', 'Override budget limit'),

-- Donations
('donations', 'view', 'donations.view', 'View donations'),
('donations', 'create', 'donations.create', 'Create/record donations'),
('donations', 'edit', 'donations.edit', 'Edit donations'),
('donations', 'delete', 'donations.delete', 'Delete donations'),
('donations', 'generate_receipt', 'donations.generate_receipt', 'Generate donation receipts'),

-- Donors
('donors', 'view', 'donors.view', 'View donors'),
('donors', 'create', 'donors.create', 'Create donors'),
('donors', 'edit', 'donors.edit', 'Edit donors'),
('donors', 'delete', 'donors.delete', 'Delete donors'),

-- Products/Inventory
('products', 'view', 'products.view', 'View products'),
('products', 'create', 'products.create', 'Create products'),
('products', 'edit', 'products.edit', 'Edit products'),
('products', 'delete', 'products.delete', 'Delete products'),
('products', 'add_stock', 'products.add_stock', 'Add stock to products'),

-- Beneficiaries
('beneficiaries', 'view', 'beneficiaries.view', 'View beneficiaries'),
('beneficiaries', 'create', 'beneficiaries.create', 'Create beneficiaries'),
('beneficiaries', 'edit', 'beneficiaries.edit', 'Edit beneficiaries'),
('beneficiaries', 'delete', 'beneficiaries.delete', 'Delete beneficiaries'),

-- Volunteers
('volunteers', 'view', 'volunteers.view', 'View volunteers'),
('volunteers', 'create', 'volunteers.create', 'Create volunteers'),
('volunteers', 'edit', 'volunteers.edit', 'Edit volunteers'),
('volunteers', 'delete', 'volunteers.delete', 'Delete volunteers'),

-- Notices
('notices', 'view', 'notices.view', 'View notices'),
('notices', 'create', 'notices.create', 'Create notices'),
('notices', 'edit', 'notices.edit', 'Edit notices'),
('notices', 'delete', 'notices.delete', 'Delete notices'),

-- Reports
('reports', 'view', 'reports.view', 'View reports'),
('reports', 'export', 'reports.export', 'Export reports'),

-- Settings
('settings', 'view', 'settings.view', 'View settings'),
('settings', 'edit', 'settings.edit', 'Edit settings'),

-- Audit Logs
('audit_logs', 'view', 'audit_logs.view', 'View audit logs'),

-- Gallery
('gallery', 'view', 'gallery.view', 'View gallery'),
('gallery', 'create', 'gallery.create', 'Upload to gallery'),
('gallery', 'delete', 'gallery.delete', 'Delete gallery items'),

-- General Expenses
('general_expenses', 'view', 'general_expenses.view', 'View general expenses'),
('general_expenses', 'create', 'general_expenses.create', 'Create general expenses'),
('general_expenses', 'edit', 'general_expenses.edit', 'Edit general expenses'),
('general_expenses', 'delete', 'general_expenses.delete', 'Delete general expenses');

-- ============================================================
-- SUPER ADMIN gets ALL permissions
-- ============================================================
INSERT INTO `role_permissions` (`role_id`, `permission_id`)
SELECT 1, id FROM `permissions`;

-- ADMIN - all except audit full delete
INSERT INTO `role_permissions` (`role_id`, `permission_id`)
SELECT 2, id FROM `permissions` WHERE slug NOT IN ('audit_logs.view');

-- MANAGER - view most, limited edit
INSERT INTO `role_permissions` (`role_id`, `permission_id`)
SELECT 3, id FROM `permissions` WHERE action = 'view';

-- CSR MANAGER - CSR focused
INSERT INTO `role_permissions` (`role_id`, `permission_id`)
SELECT 4, id FROM `permissions` WHERE module IN ('csr_companies','projects','project_expenses','project_categories','dashboard') OR slug = 'reports.view';

-- ACCOUNTANT - donations/expenses
INSERT INTO `role_permissions` (`role_id`, `permission_id`)
SELECT 5, id FROM `permissions` WHERE module IN ('donations','donors','general_expenses','reports','dashboard') OR action = 'view';

-- VOLUNTEER - limited
INSERT INTO `role_permissions` (`role_id`, `permission_id`)
SELECT 6, id FROM `permissions` WHERE slug IN ('dashboard.view','volunteers.view','projects.view','notices.view');

-- STAFF - minimal
INSERT INTO `role_permissions` (`role_id`, `permission_id`)
SELECT 7, id FROM `permissions` WHERE slug IN ('dashboard.view','notices.view');

-- ============================================================
-- DEPARTMENTS
-- ============================================================
INSERT INTO `departments` (`name`, `description`, `status`) VALUES
('Administration', 'Administrative department', 'active'),
('Finance & Accounts', 'Finance and accounting department', 'active'),
('CSR & Projects', 'CSR management and project execution', 'active'),
('Volunteer Coordination', 'Volunteer management and coordination', 'active'),
('Field Operations', 'Ground level field operations', 'active'),
('Communications', 'PR and communications', 'active');

-- ============================================================
-- DEFAULT SUPER ADMIN USER
-- Password: Admin@123 (bcrypt hashed)
-- ============================================================
INSERT INTO `users` (`user_id`, `name`, `email`, `mobile`, `password`, `designation`, `department_id`, `role_id`, `user_type`, `status`) VALUES
('USR-0001', 'Super Admin', 'admin@ngomis.com', '9999999999',
'$2y$12$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', -- password: Admin@123
'System Administrator', 1, 1, 'super_admin', 'active');

-- ============================================================
-- PROJECT CATEGORIES
-- ============================================================
INSERT INTO `project_categories` (`name`, `slug`, `description`, `status`) VALUES
('Health', 'health', 'Healthcare and medical assistance projects', 'active'),
('Health & Sanitation', 'health-sanitation', 'Health and sanitation improvement projects', 'active'),
('Education', 'education', 'Educational support and scholarship projects', 'active'),
('Environment', 'environment', 'Environmental conservation projects', 'active'),
('Women Welfare', 'women-welfare', 'Women empowerment and welfare projects', 'active'),
('Child Welfare', 'child-welfare', 'Child development and welfare projects', 'active'),
('Skill Development', 'skill-development', 'Vocational training and skill development', 'active'),
('Livelihood', 'livelihood', 'Livelihood and income generation programs', 'active'),
('Disaster Relief', 'disaster-relief', 'Emergency and disaster relief operations', 'active');

-- ============================================================
-- DEFAULT SETTINGS
-- ============================================================
INSERT INTO `settings` (`key`, `value`, `type`, `group`, `label`) VALUES
('ngo_name', 'Helping Hands NGO', 'text', 'general', 'NGO Name'),
('ngo_tagline', 'Empowering Communities, Changing Lives', 'text', 'general', 'NGO Tagline'),
('ngo_registration_number', 'REG/2024/001', 'text', 'general', 'Registration Number'),
('ngo_email', 'info@helvinghands.org', 'text', 'general', 'Email'),
('ngo_phone', '+91 98765 43210', 'text', 'general', 'Phone'),
('ngo_address', '123, NGO Complex, New Delhi - 110001', 'textarea', 'general', 'Address'),
('ngo_website', 'https://www.helpinghands.org', 'text', 'general', 'Website URL'),
('ngo_facebook', '', 'text', 'social', 'Facebook URL'),
('ngo_twitter', '', 'text', 'social', 'Twitter URL'),
('ngo_instagram', '', 'text', 'social', 'Instagram URL'),
('ngo_youtube', '', 'text', 'social', 'YouTube URL'),
('ngo_logo', '', 'file', 'general', 'NGO Logo'),
('ngo_80g_registration', '', 'text', 'legal', '80G Registration Number'),
('ngo_12a_registration', '', 'text', 'legal', '12A Registration Number'),
('ngo_pan_number', '', 'text', 'legal', 'NGO PAN Number'),
('receipt_prefix', 'RCP', 'text', 'donation', 'Receipt Number Prefix'),
('donation_id_prefix', 'DON', 'text', 'donation', 'Donation ID Prefix'),
('razorpay_key_id', '', 'text', 'payment', 'Razorpay Key ID'),
('razorpay_key_secret', '', 'text', 'payment', 'Razorpay Key Secret'),
('payment_gateway', 'razorpay', 'text', 'payment', 'Active Payment Gateway'),
('email_host', '', 'text', 'email', 'SMTP Host'),
('email_port', '587', 'text', 'email', 'SMTP Port'),
('email_username', '', 'text', 'email', 'SMTP Username'),
('email_password', '', 'text', 'email', 'SMTP Password'),
('email_from_name', 'Helping Hands NGO', 'text', 'email', 'From Name'),
('email_from_address', 'noreply@helpinghands.org', 'text', 'email', 'From Email'),
('donation_receipt_footer', 'This receipt is computer generated and does not require signature.', 'textarea', 'donation', 'Receipt Footer Text'),
('homepage_hero_title', 'Together We Can Change Lives', 'text', 'cms', 'Hero Title'),
('homepage_hero_subtitle', 'Join us in our mission to empower communities and create lasting impact.', 'textarea', 'cms', 'Hero Subtitle'),
('homepage_about', '', 'textarea', 'cms', 'About Section Content'),
('map_embed_url', '', 'text', 'contact', 'Google Maps Embed URL');
