-- Seeder: 001_admin_seeder.sql
-- Run this after the migration to populate admin roles, permissions, and the first super admin account.
-- IMPORTANT: Change the password hash before running.
-- Generate a new hash using PHP: echo password_hash('YourStrongPassword', PASSWORD_BCRYPT, ['cost' => 12]);

-- --------------------------------------------------------
-- Admin Roles
-- --------------------------------------------------------

INSERT INTO `admin_roles` (`id`, `name`, `slug`, `description`, `is_super_admin`) VALUES
(1, 'Super Admin', 'super_admin', 'Full platform access', 1),
(2, 'Support Admin', 'support_admin', 'User support access only', 0);

-- --------------------------------------------------------
-- Admin Permissions
-- --------------------------------------------------------

INSERT INTO `admin_permissions` (`id`, `name`, `slug`, `description`, `group`) VALUES
(1,  'View Users',             'view_users',             'View user list and profiles',         'users'),
(2,  'Edit Users',             'edit_users',             'Edit user profiles',                  'users'),
(3,  'Deactivate Users',       'deactivate_users',       'Deactivate and reactivate users',     'users'),
(4,  'Reset User Password',    'reset_user_password',    'Reset any user password',             'users'),
(5,  'View Subscriptions',     'view_subscriptions',     'View subscription details',           'billing'),
(6,  'Manage Subscriptions',   'manage_subscriptions',   'Extend and modify subscriptions',     'billing'),
(7,  'Grant Sync Access',      'grant_sync_access',      'Grant Google sync without payment',   'billing'),
(8,  'Revoke Sync Access',     'revoke_sync_access',     'Revoke Google sync access',           'billing'),
(9,  'View Payments',          'view_payments',          'View payment history',                'billing'),
(10, 'Process Refunds',        'process_refunds',        'Handle refund requests',              'billing'),
(11, 'Suspend Users',          'suspend_users',          'Suspend and unsuspend accounts',      'users'),
(12, 'View Audit Logs',        'view_audit_logs',        'View admin and user audit logs',      'security'),
(13, 'View Sync Logs',         'view_sync_logs',         'View Google sync logs',               'sync'),
(14, 'View Notification Logs', 'view_notification_logs', 'View notification delivery logs',     'notifications'),
(15, 'Manage Templates',       'manage_templates',       'Create and edit system templates',    'content'),
(16, 'Manage Quotes',          'manage_quotes',          'Manage motivational quotes',          'content'),
(17, 'Manage Themes',          'manage_themes',          'Create and edit themes',              'content'),
(18, 'Manage Modules',         'manage_modules',         'Configure trial module access',       'settings'),
(19, 'View Analytics',         'view_analytics',         'View platform analytics',             'analytics'),
(20, 'Manage Settings',        'manage_settings',        'Edit platform settings',              'settings'),
(21, 'View Webhook Logs',      'view_webhook_logs',      'View Stripe webhook logs',            'billing'),
(22, 'Manage Admin Users',     'manage_admin_users',     'Create and manage admin accounts',    'admin');

-- --------------------------------------------------------
-- Super Admin gets all permissions
-- --------------------------------------------------------

INSERT INTO `admin_role_permissions` (`admin_role_id`, `permission_id`) VALUES
(1, 1),(1, 2),(1, 3),(1, 4),(1, 5),(1, 6),(1, 7),(1, 8),(1, 9),(1, 10),
(1, 11),(1, 12),(1, 13),(1, 14),(1, 15),(1, 16),(1, 17),(1, 18),(1, 19),(1, 20),
(1, 21),(1, 22);

-- --------------------------------------------------------
-- Support Admin gets limited permissions
-- --------------------------------------------------------

INSERT INTO `admin_role_permissions` (`admin_role_id`, `permission_id`) VALUES
(2, 1),(2, 2),(2, 4),(2, 5),(2, 9),(2, 12),(2, 13),(2, 14);

-- --------------------------------------------------------
-- Initial Super Admin Account
-- IMPORTANT: Replace the password hash below.
-- Generate with PHP: echo password_hash('YourStrongPassword', PASSWORD_BCRYPT, ['cost' => 12]);
-- --------------------------------------------------------

INSERT INTO `admin_users` (`display_name`, `username`, `email`, `password`, `is_active`) VALUES
('Super Admin', 'superadmin', 'admin@fluppybunny.com', 'REPLACE_WITH_BCRYPT_HASH', 1);

-- Assign super admin role to the first admin user
INSERT INTO `admin_user_roles` (`admin_id`, `admin_role_id`, `assigned_at`) VALUES
(1, 1, NOW());
