<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Database\Seeders\Pages\AboutSSHIAPageSeeder;
use Database\Seeders\Pages\VisionPageSeeder;
use Database\Seeders\Pages\MissionPageSeeder;
use Database\Seeders\Pages\WhatWeDoPageSeeder;
use Database\Seeders\Pages\MembershipsPageSeeder;
use Database\Seeders\Pages\GovernancePageSeeder;
use Database\Seeders\Pages\WhatWeDoActivitiesSeeder;
use Database\Seeders\Pages\ContactUsPageSeeder;
use Database\Seeders\LandingPageSeeder;

/**
 * DatabaseSeeder
 *
 * Master seeder for the SSHIA platform. Executes all seeders in strict
 * dependency order to ensure a fully functional system on fresh install.
 *
 * Execution order:
 *   1. Roles          — must be first; all other seeders depend on roles existing
 *   2. Permissions    — ALL permission seeders run before UserSeeder so roles have
 *                       permissions before users are assigned to those roles.
 *                       PermissionPatchSeeder runs LAST in this group as a catch-all
 *                       that gives Super Manager every permission in the DB.
 *   3. Core data      — users (depend on roles), themes (no dependencies)
 *   4. Lookup data    — categories, fees, templates, settings, org data, etc.
 *   5. Content pages  — publishing pages (depend on nothing)
 *   6. Sample data    — advocacy, research, partnership demo data
 *   7. Hero content   — sliders, hero cards
 *   8. Site management sample data
 *   9. Self-Paced Learning Portal sample data (permissions already seeded in step 2)
 */
class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        $this->call([
            // ----------------------------------------------------------------
            // 1. Roles — creates all 10 system roles with correct themes
            // ----------------------------------------------------------------
            RolePermissionSeeder::class,

            // ----------------------------------------------------------------
            // 2. Permission seeders — ALL must run before UserSeeder
            //    so that roles have permissions before users are assigned.
            //    PermissionPatchSeeder is the FINAL step — it runs after every
            //    other permission seeder and gives Super Manager ALL permissions.
            // ----------------------------------------------------------------
            AuthModulePermissionSeeder::class,              // auth/user/session/theme permissions
            OrganizationPermissionSeeder::class,            // org/leadership/election permissions
            HealthDirectoryPermissionSeeder::class,         // health directory permissions
            TrainingPermissionSeeder::class,                // training module permissions
            MentorshipPermissionSeeder::class,              // mentorship module permissions
            MembershipPermissionSeeder::class,              // membership & loan permissions
            RModulePermissionSeeder::class,                 // research/advocacy/partners permissions
            KnowledgeSharingPermissionSeeder::class,        // knowledge sharing permissions
            CommunicationPermissionSeeder::class,           // email, SMS, chat, ticket permissions
            SmsPermissionSeeder::class,                     // SMS configuration permissions
            EmailConfigurationPermissionSeeder::class,      // email configuration permissions
            GoogleMeetPermissionSeeder::class,              // Google Meet permissions
            PaymentConfigurationPermissionSeeder::class,    // payment configuration permissions
            SiteManagementPermissionSeeder::class,          // topbar notifications + email subscriber permissions
            WhatWeDoImagePermissionSeeder::class,           // what we do image management permissions
            SelfPacedPermissionSeeder::class,               // self-paced learning portal permissions
            MediaPermissionSeeder::class,                   // pictorial gallery & media management permissions
            PermissionPatchSeeder::class,                   // FINAL: fixes + Super Manager catch-all (all permissions)

            // ----------------------------------------------------------------
            // 3. Core data
            // ----------------------------------------------------------------
            UserSeeder::class,          // 10 role-specific users with sshia.org emails
            ThemeSeeder::class,         // 10 role-specific dashboard themes

            // ----------------------------------------------------------------
            // 4. Lookup / reference data
            //    (ordered by dependency — fees depend on categories)
            // ----------------------------------------------------------------
            MembershipCategorySeeder::class,        // 7 official SSHIA membership categories
            SubscriptionFeeSeeder::class,           // 1 annual subscription fee per category
            ContributionFeeSeeder::class,           // 1 monthly contribution fee per category
            TrainingCategorySeeder::class,          // 6 training categories
            MentorshipCategorySeeder::class,        // 4 mentorship categories
            ChatCategorySeeder::class,              // 4 chat support categories
            ChatAgentSeeder::class,                 // default admin as chat agent (after UserSeeder)
            LoanProductSeeder::class,               // 2 loan products (Emergency + Development)
            SmsTemplateSeeder::class,               // 5 SMS templates
            EmailTemplateSeeder::class,             // 4 email templates
            SystemSettingsSeeder::class,            // 30 system settings key-value pairs
            OrganizationDataSeeder::class,          // SSHIA official organisation record
            OrganizationSocialLinksSeeder::class,   // SSHIA social media links
            PaymentConfigurationSeeder::class,      // default payment config (institution + machine)
            DiscussionTopicSeeder::class,           // 5 discussion topics
            KnowledgeBaseCategorySeeder::class,     // 5 knowledge base categories
            DiscussionSeeder::class,                // 20 discussions per topic (5 topics = 100 discussions)
            KnowledgeBaseQuestionSeeder::class,     // 20 Q&As per category (5 categories = 100 questions)

            // ----------------------------------------------------------------
            // 5. Content pages
            // ----------------------------------------------------------------
            PublishingPagesSeeder::class,
            AboutSSHIAPageSeeder::class,
            VisionPageSeeder::class,
            MissionPageSeeder::class,
            WhatWeDoPageSeeder::class,
            MembershipsPageSeeder::class,
            GovernancePageSeeder::class,
            WhatWeDoActivitiesSeeder::class,    // 9 individual "What We Do" activity pages
            ContactUsPageSeeder::class,         // slug: contact-us (nav menu link)

            // ----------------------------------------------------------------
            // 6. Sample / demo data
            // ----------------------------------------------------------------
            HealthInstitutionSeeder::class,     // 10 South Sudan health institutions
            DigitalMachineSeeder::class,        // 10 digital health equipment listings
            RAdvocacyDataSeeder::class,
            RModuleDataSeeder::class,
            RPublicationSeeder::class,
            RPartnershipDataSeeder::class,
            RPartnershipModuleSeeder::class,

            // ----------------------------------------------------------------
            // 7. Hero Slider & Info Cards + Landing Page Data
            // ----------------------------------------------------------------
            LandingPageSeeder::class,   // Angaza landing page (org, sliders, staff, galleries)
            HeroCardSeeder::class,      // homepage info cards (Red/Green/Dark Blue)

            // ----------------------------------------------------------------
            // 8. Site Management sample data
            // ----------------------------------------------------------------
            TopbarNotificationSeeder::class,    // 3 SSHIA-relevant topbar notifications

            // ----------------------------------------------------------------
            // 9. Self-Paced Learning Portal sample data
            //    Permissions were already seeded in step 2 (SelfPacedPermissionSeeder).
            //    Order: trainees → categories → courses → topics → media →
            //           downloads → exams → enrollments → results
            // ----------------------------------------------------------------
            SelfPacedTraineeSeeder::class,      // 5 sample trainee users
            SelfPacedCategorySeeder::class,     // 5 course categories

            // Professional Certificate courses (SSP)
            HealthProjectManagementCourseSeeder::class,
            LeadershipDigitalHealthCourseSeeder::class,
            HealthPolicyDataGovernanceCourseSeeder::class,
            EthicsDataProtectionCourseSeeder::class,
            ResearchMethodsBiostatisticsCourseSeeder::class,

            SelfPacedCourseSeeder::class,       // 3 sample courses
            SelfPacedTopicSeeder::class,        // 3 topics + 2 subtopics per course
            SelfPacedMediaSeeder::class,        // media attachments per subtopic
            SelfPacedDownloadSeeder::class,     // downloadable resources per course/topic
            SelfPacedExamSeeder::class,         // 12 exam questions per course
            SelfPacedEnrollmentSeeder::class,   // sample enrollments with various statuses
            SelfPacedResultSeeder::class,       // sample exam results and certificates
        ]);
    }
}
