<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\RCampaign;
use App\Models\RHealthStory;
use App\Models\RPoll;
use App\Models\RPollOption;
use App\Models\User;
use Illuminate\Support\Str;

/**
 * Seeder: RAdvocacyModuleSeeder
 * 
 * Seeds digital health advocacy content for SSHIA - South Sudan Health Innovation & Advocacy.
 * Contains campaigns, health stories, and polls related to health advocacy in South Sudan.
 * 
 * @author SSHIA Development Team
 * @version 1.0.0
 */
class RAdvocacyModuleSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $users = User::all();
        
        if ($users->isEmpty()) {
            $this->command->warn('No users found. Please run user seeder first.');
            return;
        }

        // Seed Campaigns
        $this->seedCampaigns($users);
        
        // Seed Health Stories
        $this->seedHealthStories($users);
        
        // Seed Polls
        $this->seedPolls($users);
    }

    /**
     * Seed health advocacy campaigns.
     */
    protected function seedCampaigns($users): void
    {
        $campaigns = [
            [
                'title' => 'Maternal Health for Every Mother',
                'slug' => 'maternal-health-for-every-mother',
                'description' => 'Our comprehensive maternal health campaign aims to reduce maternal mortality in South Sudan by improving access to prenatal care, skilled birth attendance, and emergency obstetric services. We work with communities to break down barriers and ensure every mother has the chance to survive and thrive.',
                'objectives' => "• Increase skilled birth attendance by 50% in target communities\n• Train 200 community health workers on maternal health\n• Establish 10 maternal waiting homes in remote areas\n• Provide emergency transport for obstetric complications\n• Engage men as partners in maternal health",
                'target_audience' => 'Women of reproductive age, pregnant women, community leaders, male partners',
                'regions' => json_encode(['Central Equatoria', 'Eastern Equatoria', 'Jonglei', 'Lakes']),
                'start_date' => '2024-01-01',
                'end_date' => '2024-12-31',
                'status' => 'active',
                'is_featured' => true,
            ],
            [
                'title' => 'Malaria-Free South Sudan',
                'slug' => 'malaria-free-south-sudan',
                'description' => 'The Malaria-Free South Sudan campaign focuses on prevention through distribution of insecticide-treated nets, indoor residual spraying, and community education. We aim to reduce malaria incidence by 40% through integrated vector management and prompt treatment access.',
                'objectives' => "• Distribute 100,000 insecticide-treated nets\n• Conduct indoor residual spraying in 50,000 households\n• Train community health workers on malaria case management\n• Establish rapid diagnostic testing points\n• Engage schools in malaria prevention education",
                'target_audience' => 'Children under 5, pregnant women, general population in high-risk areas',
                'regions' => json_encode(['Upper Nile', 'Unity', 'Jonglei', 'Central Equatoria']),
                'start_date' => '2024-03-01',
                'end_date' => '2025-02-28',
                'status' => 'active',
                'is_featured' => true,
            ],
            [
                'title' => 'Digital Health Literacy Initiative',
                'slug' => 'digital-health-literacy-initiative',
                'description' => 'Bridging the digital divide in healthcare, this initiative empowers healthcare workers and communities with digital health skills. We provide training on mobile health tools, telemedicine platforms, and health information systems to improve healthcare delivery across South Sudan.',
                'objectives' => "• Train 500 healthcare workers on digital health tools\n• Establish telemedicine connections at 20 facilities\n• Develop mobile health education content in local languages\n• Create digital health literacy curriculum for communities\n• Advocate for ICT infrastructure in health facilities",
                'target_audience' => 'Healthcare workers, community health volunteers, youth, policy makers',
                'regions' => json_encode(['Juba', 'Wau', 'Malakal', 'Yambio', 'Rumbek']),
                'start_date' => '2024-02-01',
                'end_date' => '2025-01-31',
                'status' => 'active',
                'is_featured' => true,
            ],
            [
                'title' => 'Youth Health Awareness Campaign',
                'slug' => 'youth-health-awareness-campaign',
                'description' => 'Empowering South Sudanese youth with health knowledge and life skills. This campaign addresses adolescent health issues including sexual and reproductive health, mental health, substance abuse prevention, and healthy lifestyle choices through peer education and youth-friendly services.',
                'objectives' => "• Reach 50,000 youth with health education\n• Train 200 peer educators\n• Establish youth-friendly corners at 30 health facilities\n• Develop youth health hotline and counseling services\n• Engage schools and universities in health promotion",
                'target_audience' => 'Youth aged 10-24, teachers, parents, community leaders',
                'regions' => json_encode(['Central Equatoria', 'Western Equatoria', 'Northern Bahr el Ghazal']),
                'start_date' => '2024-01-15',
                'end_date' => '2024-12-15',
                'status' => 'active',
                'is_featured' => false,
            ],
            [
                'title' => 'Immunization for All Children',
                'slug' => 'immunization-for-all-children',
                'description' => 'Every child deserves protection from vaccine-preventable diseases. This campaign strengthens routine immunization services, conducts catch-up campaigns, and addresses vaccine hesitancy through community engagement and education.',
                'objectives' => "• Achieve 80% immunization coverage in target areas\n• Conduct measles and polio supplementary immunization activities\n• Strengthen cold chain infrastructure\n• Train health workers on immunization best practices\n• Address vaccine hesitancy through community dialogue",
                'target_audience' => 'Children under 5, caregivers, traditional birth attendants',
                'regions' => json_encode(['All 10 states']),
                'start_date' => '2024-01-01',
                'end_date' => null,
                'status' => 'active',
                'is_featured' => true,
            ],
            [
                'title' => 'Clean Water, Healthy Communities',
                'slug' => 'clean-water-healthy-communities',
                'description' => 'Water-borne diseases remain a major health challenge. This campaign promotes access to clean water, sanitation facilities, and hygiene practices to reduce diarrheal diseases and improve community health outcomes.',
                'objectives' => "• Construct 50 community boreholes\n• Build sanitation facilities at 30 schools\n• Distribute water treatment supplies\n• Conduct hygiene promotion in 100 communities\n• Train community water management committees",
                'target_audience' => 'Rural communities, schools, healthcare facilities',
                'regions' => json_encode(['Jonglei', 'Unity', 'Upper Nile', 'Lakes']),
                'start_date' => '2024-04-01',
                'end_date' => '2025-03-31',
                'status' => 'active',
                'is_featured' => false,
            ],
            [
                'title' => 'Mental Health Matters',
                'slug' => 'mental-health-matters',
                'description' => 'Breaking the silence on mental health in South Sudan. This campaign raises awareness about mental health, reduces stigma, and improves access to mental health services through community-based approaches and task-shifting to trained health workers.',
                'objectives' => "• Train 100 health workers on mental health care\n• Establish support groups in 20 communities\n• Develop mental health awareness materials\n• Advocate for mental health policy implementation\n• Provide psychosocial support to conflict-affected populations",
                'target_audience' => 'General population, conflict-affected communities, healthcare workers',
                'regions' => json_encode(['Juba', 'Bor', 'Bentiu', 'Malakal']),
                'start_date' => '2024-05-01',
                'end_date' => '2025-04-30',
                'status' => 'active',
                'is_featured' => false,
            ],
            [
                'title' => 'Nutrition for Growth',
                'slug' => 'nutrition-for-growth',
                'description' => 'Addressing malnutrition among children and mothers in South Sudan. This campaign promotes optimal infant and young child feeding practices, strengthens nutrition services, and supports food security initiatives for improved nutritional outcomes.',
                'objectives' => "• Reduce acute malnutrition by 30% in target areas\n• Promote exclusive breastfeeding for first 6 months\n• Establish community nutrition programs\n• Train mothers on complementary feeding\n• Support therapeutic feeding centers",
                'target_audience' => 'Pregnant women, mothers, children under 5, community health workers',
                'regions' => json_encode(['Northern Bahr el Ghazal', 'Warrap', 'Unity', 'Jonglei']),
                'start_date' => '2024-01-01',
                'end_date' => '2024-12-31',
                'status' => 'active',
                'is_featured' => false,
            ],
            [
                'title' => 'HIV Prevention and Care',
                'slug' => 'hiv-prevention-and-care',
                'description' => 'Comprehensive HIV prevention, testing, and treatment campaign. We work to reduce new infections, eliminate mother-to-child transmission, and ensure all people living with HIV have access to life-saving treatment and support services.',
                'objectives' => "• Test 200,000 people for HIV\n• Enroll 5,000 new patients on ART\n• Achieve 95% viral suppression among patients\n• Eliminate mother-to-child transmission\n• Reduce HIV stigma through community education",
                'target_audience' => 'General population, key populations, pregnant women, youth',
                'regions' => json_encode(['Central Equatoria', 'Western Equatoria', 'Eastern Equatoria']),
                'start_date' => '2024-02-01',
                'end_date' => '2025-01-31',
                'status' => 'active',
                'is_featured' => false,
            ],
            [
                'title' => 'Healthcare Worker Safety',
                'slug' => 'healthcare-worker-safety',
                'description' => 'Protecting those who protect us. This campaign advocates for healthcare worker safety, provides personal protective equipment, offers mental health support, and promotes occupational health standards in healthcare facilities.',
                'objectives' => "• Distribute PPE to 500 health facilities\n• Train healthcare workers on infection prevention\n• Provide mental health support for frontline workers\n• Advocate for health worker safety policies\n• Establish occupational health services",
                'target_audience' => 'Healthcare workers, facility managers, policy makers',
                'regions' => json_encode(['National']),
                'start_date' => '2024-01-01',
                'end_date' => null,
                'status' => 'active',
                'is_featured' => false,
            ],
            [
                'title' => 'Community Health Champions',
                'slug' => 'community-health-champions',
                'description' => 'Empowering community members to become health advocates and change agents. This campaign trains community volunteers to promote health, provide basic services, and connect communities with the formal health system.',
                'objectives' => "• Train 1,000 community health champions\n• Establish community health committees\n• Create referral networks to health facilities\n• Develop community health action plans\n• Recognize and reward health champion achievements",
                'target_audience' => 'Community volunteers, traditional leaders, women groups, youth',
                'regions' => json_encode(['All states']),
                'start_date' => '2024-03-15',
                'end_date' => '2025-03-14',
                'status' => 'active',
                'is_featured' => false,
            ],
            [
                'title' => 'Telemedicine for Remote Care',
                'slug' => 'telemedicine-for-remote-care',
                'description' => 'Bringing specialist care to remote communities through telemedicine. This campaign establishes telemedicine connections, trains health workers on virtual consultations, and advocates for policy support for digital health solutions.',
                'objectives' => "• Connect 30 remote facilities to specialists\n• Conduct 5,000 teleconsultations\n• Train health workers on telemedicine platforms\n• Develop telemedicine protocols and guidelines\n• Advocate for telemedicine policy integration",
                'target_audience' => 'Healthcare workers in remote areas, specialists, patients',
                'regions' => json_encode(['Upper Nile', 'Jonglei', 'Unity', 'Lakes']),
                'start_date' => '2024-06-01',
                'end_date' => '2025-05-31',
                'status' => 'active',
                'is_featured' => false,
            ],
        ];

        $created = 0;
        foreach ($campaigns as $campaign) {
            RCampaign::create([
                'user_id' => $users->random()->id,
                'title' => $campaign['title'],
                'slug' => $campaign['slug'],
                'description' => $campaign['description'],
                'objectives' => $campaign['objectives'],
                'target_audience' => $campaign['target_audience'],
                'regions' => $campaign['regions'],
                'start_date' => $campaign['start_date'],
                'end_date' => $campaign['end_date'],
                'status' => $campaign['status'],
                'is_featured' => $campaign['is_featured'],
                'views_count' => rand(100, 5000),
                'stories_count' => rand(2, 15),
                'created_at' => now()->subDays(rand(30, 180)),
            ]);
            $created++;
        }

        $this->command->info("Created {$created} advocacy campaigns.");
    }

    /**
     * Seed health stories.
     */
    protected function seedHealthStories($users): void
    {
        $campaigns = RCampaign::all();
        
        $stories = [
            [
                'title' => 'How Community Health Workers Saved My Pregnancy',
                'slug' => 'community-health-workers-saved-my-pregnancy',
                'excerpt' => 'Mary\'s story of survival thanks to timely intervention by trained community health workers in rural Jonglei.',
                'content' => "My name is Mary Adut, a 28-year-old mother from Bor County in Jonglei State. When I became pregnant with my third child, I never imagined the journey that lay ahead.\n\nLiving in a remote village 40 kilometers from the nearest health facility, accessing prenatal care seemed impossible. The roads are impassable during rainy season, and the cost of transportation was beyond our means.\n\nThat's when the community health workers from SSHIA's Maternal Health program found me. They had been trained to identify high-risk pregnancies and provide basic antenatal care in the community.\n\nDuring one of their visits, the health worker noticed my blood pressure was dangerously high - a sign of preeclampsia. Without their intervention, I might not be here today. They arranged emergency transport to Bor Hospital, where I received life-saving treatment.\n\nMy baby was born healthy, and I am forever grateful. Now I advocate for other women to access the care they need. No mother should die giving life.",
                'location' => 'Bor, Jonglei State',
                'status' => 'published',
                'is_featured' => true,
                'views_count' => 1250,
            ],
            [
                'title' => 'From Village to Telemedicine: A Health Worker\'s Digital Journey',
                'slug' => 'village-to-telemedicine-health-worker-journey',
                'excerpt' => 'Health worker James Deng shares how digital health training transformed his ability to serve remote communities.',
                'content' => "For ten years, I worked as a community health worker in Lankien, a remote area of Jonglei State. We had no doctor for over 100 kilometers. Patients with complicated conditions had to travel for days to reach a hospital - many died on the way.\n\nWhen SSHIA introduced the telemedicine program, everything changed. I was trained to use a tablet to connect patients with doctors at Juba Teaching Hospital. The training was intensive but practical.\n\nMy first teleconsultation was a young boy with severe pneumonia. The doctor guided me through the assessment and treatment. The boy recovered within a week. His mother couldn't believe he was treated without traveling to Juba.\n\nSince then, I've conducted over 200 teleconsultations. I've learned to diagnose conditions I never thought possible. The digital tools have made me a better health worker.\n\nTechnology is not replacing us - it's empowering us to save more lives in our communities.",
                'location' => 'Lankien, Jonglei State',
                'status' => 'published',
                'is_featured' => true,
                'views_count' => 890,
            ],
            [
                'title' => 'Surviving Malaria: Little Akol\'s Story',
                'slug' => 'surviving-malaria-little-akol-story',
                'excerpt' => 'A mother\'s testimony of how prompt diagnosis and treatment saved her son from severe malaria.',
                'content' => "It started with a fever. My three-year-old son Akol was burning up, and I recognized the signs - malaria. In our village in Eastern Equatoria, malaria claims many young lives.\n\nIn the past, we would wait days before seeking help, trying traditional remedies first. But SSHIA had trained our community health workers and provided rapid diagnostic tests.\n\nWithin hours of symptoms appearing, our village health worker tested Akol. Positive for malaria. She started treatment immediately - the artemisinin combination therapy that SSHIA had supplied.\n\nBy the next day, his fever had broken. Within three days, he was playing again. I couldn't believe how quickly he recovered.\n\nThe health worker also gave us an insecticide-treated net and showed us how to use it properly. Now Akol sleeps protected every night.\n\nI tell every mother in our village: don't wait. Get tested early. Malaria can be treated if caught in time. My son is proof.",
                'location' => 'Torit, Eastern Equatoria State',
                'status' => 'published',
                'is_featured' => false,
                'views_count' => 650,
            ],
            [
                'title' => 'Breaking the Stigma: Living with HIV in South Sudan',
                'slug' => 'breaking-stigma-living-with-hiv-south-sudan',
                'excerpt' => 'John\'s courageous story of living positively with HIV and becoming an advocate in his community.',
                'content' => "When I tested positive for HIV five years ago, I thought my life was over. The stigma in our community was intense. People whispered. Friends stopped visiting. I felt alone.\n\nBut then I connected with SSHIA's HIV support program. The counselors helped me understand that HIV is not a death sentence. With proper treatment, I could live a normal, healthy life.\n\nI started antiretroviral therapy immediately. Within months, my viral load became undetectable. I felt stronger than I had in years.\n\nBut more importantly, I found purpose. I decided to speak openly about my status. At first, people were shocked. Some even hostile. But slowly, attitudes began to change.\n\nNow I run a support group for people living with HIV. We meet monthly to share experiences and encourage each other. Over 50 people have joined. We show our community that HIV-positive people are not victims - we are survivors, advocates, and productive members of society.\n\nMy message is simple: Know your status. Get treatment. Live positively. Stigma has no place in our fight against HIV.",
                'location' => 'Juba, Central Equatoria State',
                'status' => 'published',
                'is_featured' => true,
                'views_count' => 1450,
            ],
            [
                'title' => 'The Midwife Who Trained a Village',
                'slug' => 'midwife-who-trained-a-village',
                'excerpt' => 'Midwife Sarah\'s journey of training traditional birth attendants and transforming maternal health in her community.',
                'content' => "I have been a midwife for 20 years. In that time, I've seen too many women die from complications that could have been prevented. Traditional birth attendants (TBAs) attended most births, but they lacked formal training.\n\nWhen SSHIA started their maternal health program, I saw an opportunity. I volunteered to train TBAs in my area. The training covered clean delivery practices, recognizing danger signs, and when to refer to facilities.\n\nThe first training had 15 TBAs. Some were skeptical - they had been delivering babies for decades and didn't think they needed new methods. But when I demonstrated how simple techniques could save lives, they became eager learners.\n\nOne TBA, Mama Grace, told me she had never known why some mothers bled too much after delivery. Now she knows the signs of postpartum hemorrhage and when to seek help immediately.\n\nSince the training, maternal complications in our area have dropped by 40%. The TBAs are now our strongest advocates for facility-based deliveries. They know when they can safely assist at home and when a woman needs hospital care.\n\nKnowledge saves lives. By sharing what I know, I've multiplied my impact beyond what I could achieve alone.",
                'location' => 'Yambio, Western Equatoria State',
                'status' => 'published',
                'is_featured' => false,
                'views_count' => 720,
            ],
            [
                'title' => 'Mental Health: Finding Hope After Conflict',
                'slug' => 'mental-health-finding-hope-after-conflict',
                'excerpt' => 'A survivor\'s journey of healing from trauma through community mental health support.',
                'content' => "The conflict took everything from me - my home, my husband, my sense of safety. For years, I lived in an IDP camp, unable to sleep, haunted by nightmares. I thought I was going crazy.\n\nIn our culture, we don't talk about mental health. We say 'be strong' and 'move on.' But the pain didn't go away. I couldn't care for my children properly. I felt trapped in darkness.\n\nA community health worker from SSHIA's mental health program noticed me sitting alone every day. She approached me gently and asked how I was feeling. That simple question broke my silence.\n\nShe invited me to a support group with other women who had experienced similar trauma. At first, I was ashamed to speak. But hearing others share their stories, I realized I wasn't alone.\n\nThe counseling sessions taught me coping strategies. I learned that my reactions were normal responses to abnormal situations. Slowly, the nightmares became less frequent. I started engaging with my children again.\n\nToday, I facilitate the support group myself. I help other women find the hope I found. Mental health challenges are not weakness - they are human. And with support, healing is possible.",
                'location' => 'Juba, Central Equatoria State',
                'status' => 'published',
                'is_featured' => true,
                'views_count' => 1680,
            ],
            [
                'title' => 'The Net That Saved My Family',
                'slug' => 'net-that-saved-my-family',
                'excerpt' => 'How a simple insecticide-treated net became a family\'s best defense against malaria.',
                'content' => "Before SSHIA came to our village, my family suffered from malaria constantly. My five children would each get it three or four times a year. The medical costs were draining our resources.\n\nWhen SSHIA's malaria prevention team visited, they brought insecticide-treated nets and taught us how to use them properly. They explained that the nets not only create a barrier but the insecticide also kills mosquitoes.\n\nWe received enough nets for every sleeping space in our home. I made sure every child slept under a net every night, even during the hot season when it felt uncomfortable.\n\nThe results were remarkable. In the first year, not a single one of my children got malaria. The money we used to spend on treatment, we now invest in their education.\n\nThe nets are now three years old, and SSHIA came back to replace them. They told us the insecticide wears off over time. I'm grateful for their continued support.\n\nA simple net - costing less than a single malaria treatment - has protected my entire family. Prevention is truly better than cure.",
                'location' => 'Rumbek, Lakes State',
                'status' => 'published',
                'is_featured' => false,
                'views_count' => 540,
            ],
            [
                'title' => 'Youth Ambassador: My Journey in Health Advocacy',
                'slug' => 'youth-ambassador-health-advocacy-journey',
                'excerpt' => 'A young health advocate shares how getting involved changed her life and her community.',
                'content' => "I was 16 when I first attended a SSHIA youth health workshop. I went because my friends were going, not expecting much. But that day changed everything.\n\nThe facilitators talked about sexual and reproductive health - topics that were taboo at home. They answered questions I'd been too embarrassed to ask. They treated us with respect, not like children who shouldn't know these things.\n\nI learned about HIV prevention, family planning, gender-based violence. But more importantly, I learned that I had the power to make a difference.\n\nI became a peer educator in my school. We started a health club that meets weekly. We discuss health issues affecting young people and share accurate information.\n\nMy most proud moment was when a friend confided that she was being pressured into early marriage. I connected her with SSHIA's protection team. They worked with her family, and she's still in school today.\n\nNow I'm studying public health at university. I want to continue this work. Young people are not just the future - we are the present. We can change our communities today.",
                'location' => 'Juba, Central Equatoria State',
                'status' => 'published',
                'is_featured' => false,
                'views_count' => 880,
            ],
            [
                'title' => 'Clean Water Changed Everything',
                'slug' => 'clean-water-changed-everything',
                'excerpt' => 'A community chief tells how access to clean water transformed health in his village.',
                'content' => "As the chief of Lologo village for 15 years, I watched my people suffer. Diarrhea was constant, especially among children. Every dry season, we walked 5 kilometers to fetch water from a contaminated river. Women spent hours every day just getting water.\n\nWhen SSHIA's water and sanitation team approached us about drilling a borehole, I was skeptical. Many organizations had come with promises and left with nothing done.\n\nBut SSHIA was different. They involved us from the beginning. We formed a water management committee. We chose the location together. They trained young people to maintain the borehole.\n\nThe day clean water flowed from our borehole was a celebration. Children cheered. Women cried with joy. We had clean water right in our village.\n\nWithin months, diarrhea cases dropped dramatically. Children who were constantly sick were now healthy. Women had time for other productive activities.\n\nSSHIA also taught us about hygiene and sanitation. We built latrines and handwashing stations. The transformation in our village is visible.\n\nClean water is the foundation of health. I thank SSHIA for bringing this gift to my people.",
                'location' => 'Lologo, Central Equatoria State',
                'status' => 'published',
                'is_featured' => false,
                'views_count' => 620,
            ],
            [
                'title' => 'Breastfeeding Against All Odds',
                'slug' => 'breastfeeding-against-all-odds',
                'excerpt' => 'A mother\'s story of exclusive breastfeeding success despite challenges in an IDP camp.',
                'content' => "When my daughter Nyabie was born in the UN protection site, I was determined to breastfeed her exclusively for six months. The health workers from SSHIA had taught us about the benefits - protection from disease, better nutrition, even spacing of pregnancies.\n\nBut it wasn't easy. Living in a crowded camp with no privacy, finding a quiet space to breastfeed was difficult. The stress of displacement affected my milk supply. Well-meaning neighbors suggested I give water and porridge.\n\nThe SSHIA nutrition team visited regularly. They counseled me on proper latch and feeding positions. They created a mother-to-mother support group where we could share challenges and solutions.\n\nWhen my milk seemed insufficient, they reassured me that frequent feeding would build my supply. They were right. Within days, my baby was satisfied.\n\nSix months passed, and Nyabie had never been sick. She was growing well - a healthy, alert baby. The health workers celebrated with me.\n\nNow I'm a breastfeeding counselor myself. I help new mothers in the camp understand that breastmilk is the perfect food for their babies. It's free, always available, and provides everything a baby needs for the first six months.\n\nEven in difficult circumstances, we can give our children the best start in life.",
                'location' => 'Juba Protection of Civilians Site',
                'status' => 'published',
                'is_featured' => false,
                'views_count' => 790,
            ],
            [
                'title' => 'Radio Saved Lives: Health Messages Through Airwaves',
                'slug' => 'radio-saved-lives-health-messages',
                'excerpt' => 'How radio health programs reached remote communities with life-saving information.',
                'content' => "In our village in Northern Bahr el Ghazal, radio is king. Most people can't read, but everyone listens to the radio. When SSHIA started broadcasting health programs in Dinka, it transformed our community.\n\nThe programs covered everything from maternal health to malaria prevention, from HIV to nutrition. They used drama, songs, and real stories to make the messages memorable.\n\nI remember an episode about the importance of delivering in health facilities. The drama showed a woman with complications who was saved because she went to the clinic. After that broadcast, our health facility saw a 30% increase in facility deliveries.\n\nAnother episode taught about the signs of pneumonia in children. A week later, a neighbor recognized the danger signs in her baby and rushed him to the clinic. The health worker told her the broadcast had saved her son's life.\n\nI now lead a radio listening group. We gather weekly to listen and discuss. The messages spread further as members share what they learn with neighbors.\n\nRadio breaks barriers. It reaches the unreachable. It educates without requiring literacy. SSHIA understood this and used it brilliantly.",
                'location' => 'Aweil, Northern Bahr el Ghazal State',
                'status' => 'published',
                'is_featured' => false,
                'views_count' => 480,
            ],
            [
                'title' => 'The Immunization Champion',
                'slug' => 'immunization-champion',
                'excerpt' => 'A father\'s story of becoming an advocate for childhood vaccinations.',
                'content' => "My name is Deng, and I admit I was skeptical about vaccines. Rumors in our community said they could harm children or were part of a foreign plot. When the vaccination teams came, I hid my children.\n\nThen SSHIA organized a community dialogue. Health workers, elders, and religious leaders came together. They explained how vaccines work and answered all our questions. A doctor from Juba shared data showing that diseases like measles had nearly disappeared where vaccination rates were high.\n\nWhat convinced me most was a mother who testified. Her child had died of measles years before vaccines were available. She urged us to take advantage of this protection.\n\nI brought my children for vaccination that same week. The process was quick and professional. The health worker gave me a vaccination card and explained when to return.\n\nToday, all my children are fully vaccinated. They are healthy and strong. I've become an immunization champion in my community. I talk to other fathers who are hesitant.\n\nVaccines are a gift. They protect our children from diseases that used to kill many. I'm grateful I learned the truth before it was too late.",
                'location' => 'Wau, Western Bahr el Ghazal State',
                'status' => 'published',
                'is_featured' => false,
                'views_count' => 560,
            ],
            [
                'title' => 'Digital Health Reaches the Last Mile',
                'slug' => 'digital-health-reaches-last-mile',
                'excerpt' => 'How mobile health applications are connecting remote health facilities to the health information system.',
                'content' => "Working at a primary health care center in Pibor, I used to dread the monthly reporting. We would fill paper forms by hand, then someone had to travel for days to deliver them to the county health office. Often, reports were lost or arrived too late to be useful.\n\nWhen SSHIA introduced the mobile reporting system, I was nervous. I had never used a smartphone before. The training was patient and thorough. Within a week, I was comfortable.\n\nNow I enter patient data directly into the mobile application. The system works even without internet - it syncs when connectivity is available. The county health office receives our data in real-time.\n\nThis has changed everything. When we had a cholera outbreak, we reported it immediately. The response team arrived within 48 hours. In the past, we would have waited weeks for help.\n\nThe application also gives us decision-support tools. It helps identify children who need vaccinations, pregnant women due for visits, and patients who need follow-up.\n\nTechnology is not just for cities. With the right tools and training, we in remote areas can provide the same quality of care as anywhere else.",
                'location' => 'Pibor, Jonglei State',
                'status' => 'published',
                'is_featured' => false,
                'views_count' => 380,
            ],
        ];

        $created = 0;
        foreach ($stories as $story) {
            $user = $users->random();
            RHealthStory::create([
                'campaign_id' => $campaigns->isNotEmpty() ? $campaigns->random()->id : null,
                'user_id' => rand(0, 1) ? $user->id : null,
                'author_name' => rand(0, 1) ? null : 'Guest Author',
                'author_email' => rand(0, 1) ? null : 'guest@example.com',
                'title' => $story['title'],
                'slug' => $story['slug'],
                'excerpt' => $story['excerpt'],
                'content' => $story['content'],
                'location' => $story['location'],
                'status' => $story['status'],
                'is_featured' => $story['is_featured'],
                'views_count' => $story['views_count'],
                'shares_count' => rand(10, 200),
                'published_at' => now()->subDays(rand(10, 180)),
                'moderated_by' => $users->random()->id,
                'moderated_at' => now()->subDays(rand(5, 30)),
                'created_at' => now()->subDays(rand(30, 200)),
            ]);
            $created++;
        }

        $this->command->info("Created {$created} health stories.");
    }

    /**
     * Seed polls with options.
     */
    protected function seedPolls($users): void
    {
        $campaigns = RCampaign::all();
        
        $polls = [
            [
                'question' => 'What is the most important health challenge facing your community?',
                'description' => 'Help us understand community health priorities to better target our programs and advocacy efforts.',
                'poll_type' => 'single_choice',
                'options' => ['Malaria', 'Maternal Health', 'HIV/AIDS', 'Water-borne Diseases', 'Malnutrition', 'Mental Health'],
            ],
            [
                'question' => 'How do you prefer to receive health information?',
                'description' 'Your feedback helps us design more effective health communication strategies.',
                'poll_type' => 'multiple_choice',
                'max_selections' => 3,
                'options' => ['Radio', 'Community Meetings', 'Health Workers', 'Social Media', 'SMS Messages', 'Printed Materials'],
            ],
            [
                'question' => 'Have you or a family member used telemedicine services?',
                'description' => 'As we expand digital health services, we want to understand current telemedicine awareness and usage.',
                'poll_type' => 'single_choice',
                'options' => ['Yes, very helpful', 'Yes, but prefer in-person', 'No, but interested', 'No, never heard of it'],
            ],
            [
                'question' => 'What barriers prevent you from accessing healthcare? (Select up to 2)',
                'description' => 'Understanding access barriers helps us advocate for healthcare system improvements.',
                'poll_type' => 'multiple_choice',
                'max_selections' => 2,
                'options' => ['Distance to facility', 'Cost of services', 'Lack of medicines', 'No female staff', 'Long waiting times', 'Fear/stigma'],
            ],
            [
                'question' => 'Do you sleep under an insecticide-treated net every night?',
                'description' => 'This data helps us measure malaria prevention coverage and plan net distribution campaigns.',
                'poll_type' => 'single_choice',
                'options' => ['Yes, every night', 'Most nights', 'Rarely', 'Never', 'I don\'t have a net'],
            ],
            [
                'question' => 'What digital health service would benefit your community most?',
                'description' => 'Your input guides our digital health strategy and investment priorities.',
                'poll_type' => 'single_choice',
                'options' => ['Telemedicine consultations', 'Health SMS reminders', 'Mobile health records', 'Online health education', 'Disease surveillance alerts'],
            ],
            [
                'question' => 'How satisfied are you with maternal health services in your area?',
                'description' => 'Your feedback helps us improve maternal health programs and advocate for better services.',
                'poll_type' => 'single_choice',
                'options' => ['Very satisfied', 'Satisfied', 'Neutral', 'Dissatisfied', 'Very dissatisfied', 'No services available'],
            ],
            [
                'question' => 'Which vaccination campaigns are you aware of in your community?',
                'description' => 'Help us assess vaccination campaign awareness and improve community outreach.',
                'poll_type' => 'multiple_choice',
                'max_selections' => 4,
                'options' => ['Measles', 'Polio', 'COVID-19', 'Tetanus', 'Pneumonia', 'Cholera', 'None'],
            ],
            [
                'question' => 'What type of mental health support does your community need most?',
                'description' => 'Your input shapes our mental health programming and advocacy priorities.',
                'poll_type' => 'single_choice',
                'options' => ['Counseling services', 'Support groups', 'Community awareness', 'Training for health workers', 'Integration with primary care', 'Trauma support'],
            ],
            [
                'question' => 'How has the Digital Health Literacy Initiative impacted you?',
                'description' => 'We want to measure the impact of our digital health training programs.',
                'poll_type' => 'single_choice',
                'options' => ['Significantly improved my work', 'Somewhat helpful', 'Participated but not applicable', 'Not aware of the program', 'No access to training'],
            ],
            [
                'question' => 'What is the primary source of drinking water in your household?',
                'description' => 'This data informs our water and sanitation programming priorities.',
                'poll_type' => 'single_choice',
                'options' => ['Borehole/pump', 'Protected well', 'Unprotected well', 'River/stream', 'Rainwater collection', 'Piped water'],
            ],
            [
                'question' => 'Which health topics would you like more information about?',
                'description' => 'Help us develop relevant health education content for our programs.',
                'poll_type' => 'multiple_choice',
                'max_selections' => 3,
                'options' => ['Family planning', 'Child nutrition', 'HIV prevention', 'Maternal health', 'Mental health', 'Hygiene and sanitation', 'Chronic diseases'],
            ],
        ];

        $created = 0;
        foreach ($polls as $index => $pollData) {
            $poll = RPoll::create([
                'campaign_id' => $campaigns->isNotEmpty() ? $campaigns->random()->id : null,
                'user_id' => $users->random()->id,
                'question' => $pollData['question'],
                'description' => $pollData['description'],
                'poll_type' => $pollData['poll_type'],
                'max_selections' => $pollData['max_selections'] ?? 1,
                'status' => 'active',
                'is_featured' => $index < 3,
                'starts_at' => now()->subDays(rand(10, 60)),
                'ends_at' => rand(0, 1) ? now()->addDays(rand(30, 90)) : null,
                'total_responses' => rand(100, 2000),
                'created_at' => now()->subDays(rand(30, 120)),
            ]);

            // Create options
            $colors = ['#10B981', '#3B82F6', '#F59E0B', '#EF4444', '#8B5CF6', '#EC4899', '#6366F1'];
            foreach ($pollData['options'] as $order => $optionText) {
                RPollOption::create([
                    'poll_id' => $poll->id,
                    'option_text' => $optionText,
                    'sort_order' => $order,
                    'color' => $colors[$order % count($colors)],
                    'votes_count' => rand(20, 500),
                ]);
            }
            $created++;
        }

        $this->command->info("Created {$created} polls with options.");
    }
}
