-- Seed: Default permissions
INSERT INTO permissions (slug, name, module) VALUES
-- Consumers
('consumers.view', 'View Consumers', 'consumers'),
('consumers.create', 'Create Consumers', 'consumers'),
('consumers.update', 'Update Consumers', 'consumers'),
('consumers.delete', 'Delete Consumers', 'consumers'),
('consumers.export', 'Export Consumer Data', 'consumers'),
('consumers.import', 'Import Consumers', 'consumers'),
-- Staff
('staff.view', 'View Staff', 'staff'),
('staff.create', 'Create Staff', 'staff'),
('staff.edit', 'Edit Staff', 'staff'),
('staff.update', 'Update Staff', 'staff'),
('staff.delete', 'Delete Staff', 'staff'),
('staff.export', 'Export Staff Records', 'staff'),
-- ISP
('isp.view', 'View ISPs', 'isp'),
('isp.create', 'Create ISPs', 'isp'),
('isp.update', 'Update ISPs', 'isp'),
('isp.approve', 'Approve ISPs', 'isp'),
('isp.delete', 'Delete ISPs', 'isp'),
-- MAR
('mar.view', 'View MAR', 'mar'),
('mar.sign', 'Sign MAR Entries', 'mar'),
('mar.create', 'Create Medications', 'mar'),
('mar.update', 'Update Medications', 'mar'),
('mar.delete', 'Delete Medications', 'mar'),
('mar.override', 'Override MAR Entries', 'mar'),
-- Incidents
('incidents.view', 'View Incidents', 'incidents'),
('incidents.create', 'Report Incidents', 'incidents'),
('incidents.update', 'Update Incidents', 'incidents'),
('incidents.resolve', 'Resolve Incidents', 'incidents'),
('incidents.delete', 'Delete Incidents', 'incidents'),
('incidents.export', 'Export Incidents', 'incidents'),
-- Compliance
('compliance.view', 'View Compliance', 'compliance'),
('compliance.create_audit', 'Create Audits', 'compliance'),
('compliance.edit', 'Edit Compliance', 'compliance'),
('compliance.run_audit', 'Run Compliance Audits', 'compliance'),
('compliance.manage_standards', 'Manage Standards', 'compliance'),
('compliance.resolve_findings', 'Resolve Findings', 'compliance'),
-- Schedule
('schedule.view', 'View Schedule', 'schedule'),
('schedule.create', 'Create Events', 'schedule'),
('schedule.edit', 'Edit Events', 'schedule'),
('schedule.update', 'Update Events', 'schedule'),
('schedule.delete', 'Delete Events', 'schedule'),
-- Documents
('documents.view', 'View Documents', 'documents'),
('documents.upload', 'Upload Documents', 'documents'),
('documents.delete', 'Delete Documents', 'documents'),
('documents.manage_folders', 'Manage Folders', 'documents'),
-- Training
('training.view', 'View Training', 'training'),
('training.assign', 'Assign Training', 'training'),
('training.complete', 'Complete Training', 'training'),
('training.manage', 'Manage Training', 'training'),
('training.manage_courses', 'Manage Courses', 'training'),
-- Reports
('reports.view', 'View Reports', 'reports'),
('reports.generate', 'Generate Reports', 'reports'),
('reports.schedule', 'Schedule Reports', 'reports'),
-- Notifications
('notifications.view', 'View Notifications', 'notifications'),
('notifications.send', 'Send Notifications', 'notifications'),
('notifications.manage', 'Manage Notifications', 'notifications'),
-- AI Agents
('ai_agents.use', 'Use AI Features', 'ai_agents'),
('ai_agents.configure', 'Configure AI', 'ai_agents'),
-- Admin
('admin.users', 'Manage Users', 'admin'),
('admin.roles', 'Manage Roles', 'admin'),
('admin.settings', 'Manage Settings', 'admin'),
('admin.modules', 'Manage Modules', 'admin'),
('admin.billing', 'Manage Billing', 'admin'),
('admin.audit_log', 'View Audit Log', 'admin');

-- Seed: Default roles
INSERT INTO roles (slug, name, description, level, is_system, location_restricted, consumer_restricted) VALUES
('org_admin', 'Organization Administrator', 'Full access within their organization', 90, 1, 0, 0),
('program_director', 'Program Director', 'Oversees all programs and locations', 80, 1, 0, 0),
('program_manager', 'Program Manager', 'Manages specific residential location(s)', 70, 1, 1, 0),
('qidp', 'QIDP', 'ISP development and coordination (42 CFR 483.430)', 65, 1, 0, 0),
('rn', 'Registered Nurse', 'Medical oversight and MAR review', 65, 1, 0, 0),
('lpn', 'Licensed Practical Nurse', 'Medication administration under RN supervision', 55, 1, 0, 0),
('case_manager', 'Case Manager', 'External coordination and consumer advocacy', 50, 1, 0, 1),
('hr_coordinator', 'HR/Training Coordinator', 'Staff records and training management', 55, 1, 0, 0),
('dsp', 'Direct Support Professional', 'Day-to-day care and documentation', 40, 1, 1, 1),
('auditor', 'Auditor / Read-Only', 'View-only access for compliance reviews', 20, 1, 0, 0);

-- Seed: Default compliance standards (Missouri DMH)
INSERT INTO compliance_standards (code, title, category, regulation_source) VALUES
('9CSR45-5.010(1)', 'General Provisions - Residential Services', 'General', '9 CSR 45-5.010'),
('9CSR45-5.010(2)', 'Personnel Requirements', 'Staff', '9 CSR 45-5.010'),
('9CSR45-5.010(3)', 'Staff Training Requirements', 'Training', '9 CSR 45-5.010'),
('9CSR45-5.010(4)', 'Medication Management', 'Medical', '9 CSR 45-5.010'),
('9CSR45-5.010(5)', 'Individual Rights', 'Rights', '9 CSR 45-5.010'),
('9CSR45-5.010(6)', 'Habilitation Services', 'Services', '9 CSR 45-5.010'),
('9CSR45-5.010(7)', 'Health and Safety', 'Safety', '9 CSR 45-5.010'),
('9CSR45-5.010(8)', 'Physical Environment', 'Environment', '9 CSR 45-5.010'),
('9CSR40-1.010', 'Certification Requirements', 'Certification', '9 CSR 40-1'),
('9CSR40-1.020', 'Application for Certification', 'Certification', '9 CSR 40-1'),
('9CSR10-5.200', 'Individual Rights of Persons Served', 'Rights', '9 CSR 10-5.200'),
('42CFR483.410', 'Condition: Governing Body', 'Federal', '42 CFR 483'),
('42CFR483.420', 'Condition: Client Protections', 'Federal', '42 CFR 483'),
('42CFR483.430', 'Condition: Facility Staffing', 'Federal', '42 CFR 483'),
('42CFR483.440', 'Condition: Active Treatment', 'Federal', '42 CFR 483'),
('42CFR483.450', 'Condition: Client Behavior/Facility Practices', 'Federal', '42 CFR 483'),
('42CFR483.460', 'Condition: Health Care Services', 'Federal', '42 CFR 483'),
('42CFR483.470', 'Condition: Physical Environment', 'Federal', '42 CFR 483'),
('42CFR483.480', 'Condition: Dietetic Services', 'Federal', '42 CFR 483');

-- Seed: Default training courses (DMH required)
INSERT INTO training_courses (title, category, duration_hours, renewal_months, required_by_dmh) VALUES
('CPR & First Aid Certification', 'safety', 8, 24, 1),
('Medication Administration (Level 1)', 'medical', 16, 12, 1),
('Abuse, Neglect & Exploitation Prevention', 'compliance', 4, 12, 1),
('Individual Rights', 'compliance', 2, 12, 1),
('Behavioral Support & De-escalation', 'professional', 8, 12, 1),
('Fire Safety & Evacuation', 'safety', 2, 12, 1),
('HIPAA Compliance', 'compliance', 2, 12, 1),
('Bloodborne Pathogens', 'safety', 2, 12, 1),
('Mandated Reporter Training', 'compliance', 2, 12, 1),
('Person-Centered Planning', 'professional', 4, 24, 1),
('Documentation Standards', 'professional', 4, 12, 1),
('New Employee Orientation', 'general', 40, NULL, 0),
('Seizure Management', 'medical', 4, 12, 1),
('Choking/Dysphagia Management', 'medical', 2, 12, 1),
('Wheelchair & Transfer Safety', 'safety', 4, 24, 0);
