<?php

namespace Database\Seeders;

use App\Models\Course;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

/**
 * A free, real video course built from Rina Hicks' own Money-Wise YouTube
 * channel (youtube.com/@MoneyWiseWithRinaHicks, channel UCN6_Kze4Oan1grlfbH-faig).
 * Every lesson embeds an actual published video, this is the client's own
 * content, so embedding is appropriate.
 */
class MoneyFoundationsSeeder extends Seeder
{
    private function yt(string $id): string
    {
        return "https://www.youtube.com/watch?v={$id}";
    }

    public function run(): void
    {
        $course = Course::updateOrCreate(
            ['slug' => 'money-foundations'],
            [
                'title' => 'Money Foundations with Rina Hicks',
                'subtitle' => 'A free video masterclass, the core money lessons Rina has taught 1,500+ people, straight from the Money-Wise channel.',
                'description' => "Start here. This free course pulls the most important lessons from the Money-Wise YouTube channel into one guided path, from the mindset that builds wealth, to managing your salary, escaping debt, and your first real investments.\n\nEvery lesson is a short, jargon-free video you can watch at your own pace. By the end you'll have the foundation every other Money-Wise course builds on.",
                'emoji' => 'play',
                'cover_path' => 'images/stock/learning.jpg',
                'level' => 'beginner',
                'price_kes' => 0,
                'price_usd' => 0,
                'is_published' => true,
                'sort' => 1,
                'outcomes' => [
                    'Understand what money really means to you, and the mindset that builds wealth',
                    'Make the most of every salary with a system for saving and multiple income streams',
                    'Break the debt cycle for good and rebuild on solid ground',
                    'Take your first confident steps into SACCOs, money market funds and investing',
                ],
            ]
        );

        $course->modules()->delete();

        $modules = [
            [
                'title' => 'Money mindset & foundations',
                'summary' => 'Before the numbers: what money means to you, and the habits that quietly build (or break) wealth.',
                'lessons' => [
                    ['title' => 'What Does Money Mean to You?', 'video' => 'GSR-_GKdpkA', 'duration' => 9, 'free' => true,
                     'summary' => 'The starting point of every money journey, getting honest about your relationship with money.'],
                    ['title' => 'What God Teaches About Money Most People Ignore', 'video' => '8DjUiXKzDU0', 'duration' => 14,
                     'summary' => 'A values-first look at stewardship, generosity and wealth.'],
                    ['title' => 'My First Money Move', 'video' => 'vHDneOk44a8', 'duration' => 8,
                     'summary' => 'The very first step to take when you decide to get serious about money.'],
                    ['title' => 'Cultivating Financial Discipline', 'video' => 'sDx69ILNU5M', 'duration' => 11,
                     'summary' => 'Discipline beats income. How to build the habits that make every plan stick.'],
                ],
            ],
            [
                'title' => 'Make the most of your income',
                'summary' => 'Your salary is the seed. Here is how to manage it, stretch it, and grow more income streams.',
                'lessons' => [
                    ['title' => 'Managing Your Salary', 'video' => 'qyhCOK7mlJA', 'duration' => 12,
                     'summary' => 'A practical framework for splitting and directing every pay cheque.'],
                    ['title' => 'One Income Is Too Close to None', 'video' => '9bL6GQ7Kqgw', 'duration' => 15,
                     'summary' => 'Why a single income is a risk, and how to build multiple streams.'],
                    ['title' => 'The Power of Passive Income Streams', 'video' => 'BQDmN1azetg', 'duration' => 16,
                     'summary' => 'Making your money work while you sleep, the realistic way.'],
                ],
            ],
            [
                'title' => 'Break free from debt',
                'summary' => 'The honest truth about the debt trap, and how to climb out and stay out.',
                'lessons' => [
                    ['title' => 'The Debt Trap No One Warned You About', 'video' => '6UtxOEqqWjk', 'duration' => 13,
                     'summary' => 'How modern debt sneaks up on you, and the first move to make.'],
                    ['title' => 'Drowning in Debt to Look Successful, The Bob Story', 'video' => 'iWtofe6Z5F8', 'duration' => 12,
                     'summary' => 'A cautionary real-world story about lifestyle debt.'],
                    ['title' => "Love, Lies & Debt: What They're Not Telling You", 'video' => 'gXgZmU0Ag5g', 'duration' => 14,
                     'summary' => 'Money, relationships and the conversations couples avoid.'],
                ],
            ],
            [
                'title' => 'Save & grow with SACCOs and MMFs',
                'summary' => "Africa's most practical saving and growth vehicles, explained simply.",
                'lessons' => [
                    ['title' => 'Money Market Funds Explained', 'video' => 'VYRoZ0SvDJs', 'duration' => 12,
                     'summary' => 'The low-risk vehicle every saver should understand.'],
                    ['title' => 'Why Join a SACCO?', 'video' => '4aqPRS6YwDs', 'duration' => 10,
                     'summary' => 'The case for SACCOs as a savings and credit foundation.'],
                    ['title' => 'What to Look at When Choosing a SACCO', 'video' => '1Sbacsl9Cww', 'duration' => 11,
                     'summary' => 'How to pick a SACCO that is safe and right for you.'],
                    ['title' => 'The Benefits of a SACCO', 'video' => '8aNf5j8sMFc', 'duration' => 9,
                     'summary' => 'What you actually gain by becoming a member.'],
                ],
            ],
            [
                'title' => 'Take your first investing steps',
                'summary' => 'From life-stage money moves to positioning a real portfolio, and claiming what is already yours.',
                'lessons' => [
                    ['title' => 'Money Moves for Every Life Stage', 'video' => 'xJtJ_LxcgwE', 'duration' => 17,
                     'summary' => 'The right money priorities for each season of life.'],
                    ['title' => 'Positioning Your Portfolio for 2026', 'video' => 'Fig5U02DMwc', 'duration' => 20,
                     'summary' => 'A high-level webinar on building a portfolio for the year ahead.'],
                    ['title' => 'Unclaimed Assets, Is Money Waiting for You?', 'video' => 'FXDITlMuXGY', 'duration' => 8,
                     'summary' => 'How to find and claim financial assets you may have forgotten.'],
                ],
            ],
            [
                'title' => 'Bonus: reading a real IPO (Kenya Pipeline)',
                'summary' => 'A six-part deep dive breaking down a real listing with @cta101, see the analysis in action.',
                'lessons' => [
                    ['title' => 'Kenya Pipeline IPO, Part 1', 'video' => 'r-X-9zR8sbI', 'duration' => 15],
                    ['title' => 'Kenya Pipeline IPO, Part 2', 'video' => 'jBGaYHiilu4', 'duration' => 15],
                    ['title' => 'Kenya Pipeline IPO, Part 3', 'video' => '_aIxfOhbckU', 'duration' => 15],
                    ['title' => 'Kenya Pipeline IPO, Part 4', 'video' => 'LHoNyWsX2Is', 'duration' => 15],
                    ['title' => 'Kenya Pipeline IPO, Part 5', 'video' => '3CpiCr67nNE', 'duration' => 15],
                    ['title' => 'Kenya Pipeline IPO, Part 6', 'video' => 'KdDRkaqmwW4', 'duration' => 15],
                ],
            ],
        ];

        foreach ($modules as $mIndex => $moduleData) {
            $module = $course->modules()->create([
                'title' => $moduleData['title'],
                'summary' => $moduleData['summary'] ?? null,
                'sort' => $mIndex,
            ]);

            foreach ($moduleData['lessons'] as $lIndex => $lesson) {
                $module->lessons()->create([
                    'title' => $lesson['title'],
                    'slug' => Str::slug($lesson['title']),
                    'summary' => $lesson['summary'] ?? null,
                    'video_url' => $this->yt($lesson['video']),
                    'duration_minutes' => $lesson['duration'],
                    'is_free_preview' => $lesson['free'] ?? false,
                    'sort' => $lIndex,
                ]);
            }
        }
    }
}
