<?php

namespace Database\Seeders;

use App\Models\Assessment;
use Illuminate\Database\Seeder;

/**
 * Money Personalities, the real Money-Wise assessment.
 * Adapted from "Money Harmony" by Olivia Mellan & Sherry Christie.
 * Five types: Hoarder (H), Spender (S), Money Monk (M), Avoider (V), Amasser (A).
 * 20 statements, one option per type each; the dominant type is your result.
 */
class MoneyPersonalitySeeder extends Seeder
{
    /** Type icons (reused per option so each question shows one icon per type). */
    private const ICON = [
        'hoarder' => 'shield-check',
        'spender' => 'sparkles',
        'monk' => 'heart',
        'avoider' => 'meh',
        'amasser' => 'trending-up',
    ];

    public function run(): void
    {
        $assessment = Assessment::updateOrCreate(
            ['slug' => 'money-personality'],
            [
                'title' => 'Money Personality Test',
                'tagline' => 'Who are you with money, really? 20 honest statements reveal your dominant money type.',
                'description' => 'There are no right or wrong answers and no winning type. Knowing your money personality shows you your natural strengths, and the blind spot quietly costing you. Adapted from "Money Harmony" by Olivia Mellan & Sherry Christie.',
                'emoji' => 'users',
                'est_minutes' => 5,
                'cooldown_days' => 60,
                'is_active' => true,
                'settings' => [
                    'mode' => 'profile',
                    'types' => [
                        'hoarder' => 'The Hoarder',
                        'spender' => 'The Spender',
                        'monk' => 'The Money Monk',
                        'avoider' => 'The Avoider',
                        'amasser' => 'The Amasser',
                    ],
                ],
            ]
        );

        $assessment->allQuestions()->delete();
        $assessment->bands()->delete();

        // Each question: prompt + 5 options in order a-e, tagged with their type.
        $questions = [
            ['If KES 2 million came to me unexpectedly, my first impulse would be to:', [
                ['Spend it on things I want, including gifts for others', 'spender'],
                ['Immediately put it somewhere safe so it won\'t get wasted away', 'hoarder'],
                ['Put off making any decisions until I felt less overwhelmed', 'avoider'],
                ['Figure out ways of investing it to get the best possible return', 'amasser'],
                ['Give most of it away to organisations that can make the world a better place', 'monk'],
            ]],
            ['Here\'s how I feel about my money:', [
                ['I make sure it never influences my life choices', 'monk'],
                ['I enjoy spending it on gifts and anything else that gives me pleasure', 'spender'],
                ['I think about it a lot and strategise how to make more of it', 'amasser'],
                ['I hold onto it and enjoy thinking about the security it provides', 'hoarder'],
                ['I try not to think about it and hope it will take care of itself', 'avoider'],
            ]],
            ['My primary financial objective is…', [
                ['To save enough money now so I never have to worry about my old age', 'hoarder'],
                ['Unclear to me', 'avoider'],
                ['To have enough of it to make sure I can buy whatever I want', 'spender'],
                ['To have enough to satisfy my basic needs and then give the rest away', 'monk'],
                ['To make as much of it as possible as quickly as possible', 'amasser'],
            ]],
            ['Here\'s how I feel about budgeting:', [
                ['I take a lot of time figuring out how to have more money to spend and save', 'amasser'],
                ['I take pride in following my budget closely', 'hoarder'],
                ['I take pride in living so simply that I never need a budget', 'monk'],
                ['Budget? Yuck! Just hearing the word makes me want to rebel', 'spender'],
                ['I don\'t have a budget and wouldn\'t know how to start. I hope my money will take care of itself', 'avoider'],
            ]],
            ['Here\'s how I feel about spending:', [
                ['I hope I have enough money to take care of unexpected expenses', 'avoider'],
                ['I enjoy spending, as long as I keep earning and saving more and my net worth keeps increasing', 'amasser'],
                ['I\'d rather save my money; spending makes me nervous', 'hoarder'],
                ['I don\'t care where my money goes; I have more important things to think about', 'monk'],
                ['I love spending money, and I tend to spend more than I earn', 'spender'],
            ]],
            ['Here\'s how I feel about financial record keeping:', [
                ['I love to look at my old statements to see how much more money I have now', 'amasser'],
                ['I am not sure which records I should be keeping', 'avoider'],
                ['I enjoy keeping careful records', 'hoarder'],
                ['I keep track of things on and off', 'spender'],
                ['I don\'t keep records. There are more important things in life', 'monk'],
            ]],
            ['Here\'s how I feel about saving:', [
                ['I know I ought to be saving, but I never seem to get around to it', 'avoider'],
                ['I really enjoy saving, the more the better!', 'amasser'],
                ['I have trouble saving money, which bothers me sometimes', 'spender'],
                ['If I had enough money to save, I would give it away instead', 'monk'],
                ['Saving comes naturally to me. I am regular and consistent about it', 'hoarder'],
            ]],
            ['Here\'s how I feel about borrowing:', [
                ['I try not to borrow because it\'s easy to lose track of paying it back', 'avoider'],
                ['It\'s rare for me to borrow, because I have enough saved for emergencies', 'hoarder'],
                ['I\'m willing to borrow to make money, but I dislike having lots of debt', 'amasser'],
                ['I\'ve borrowed quite often, but I can\'t say I\'ve always paid it back', 'spender'],
                ['I hate debt and would borrow only for absolute necessities', 'monk'],
            ]],
            ['Here\'s how I feel about lending money:', [
                ['I\'m pretty generous and don\'t worry too much about getting it back', 'spender'],
                ['People tend not to ask me for money. They know I probably don\'t have any extra', 'monk'],
                ['I have no idea whether I could afford to lend anyone money', 'avoider'],
                ['I try never to lend, but if I do, I feel tense about it until it\'s repaid', 'hoarder'],
                ['I don\'t mind lending at a good interest rate, if I get repaid on time', 'amasser'],
            ]],
            ['Here\'s how I feel about credit cards:', [
                ['I don\'t like credit cards, and think people who use them are asking for trouble', 'monk'],
                ['I use credit cards a lot and tend to make the minimum payment most of the time', 'spender'],
                ['I don\'t mind running up a large balance, as long as I can pay it off quickly', 'amasser'],
                ['I\'m often surprised by how much I owe, especially when late fees are added in', 'avoider'],
                ['I\'ve always tended to avoid credit. I prefer paying by debit card or cash', 'hoarder'],
            ]],
            ['In the event of a financial emergency…', [
                ['I don\'t know if I have enough saved, so I just hope for the best', 'avoider'],
                ['I hope I could rely on friends or bartering services', 'monk'],
                ['I never have enough money left over to save for emergencies', 'spender'],
                ['I\'ve put aside a sizable amount for emergencies, but I\'m not sure it\'s enough', 'amasser'],
                ['I\'ve saved enough for almost any emergency, but hope I never have to spend it', 'hoarder'],
            ]],
            ['Here\'s how I feel about paying taxes:', [
                ['I\'m always astonished to find out how much tax I owe', 'avoider'],
                ['I save regularly for taxes, and usually file my return well before it\'s due', 'hoarder'],
                ['I hate the whole thing and try to get it done with as little fuss as possible', 'monk'],
                ['I always have to scramble to get my return done and find cash to pay my taxes', 'spender'],
                ['I take pride in paying taxes on my increased income, if I can', 'amasser'],
            ]],
            ['To feel totally satisfied with my annual income, I would need…', [
                ['My employer to match every shilling I put into my pension', 'hoarder'],
                ['At least twice as much as I\'m earning now', 'amasser'],
                ['I\'m sure I could use more money, but I have no idea how much', 'avoider'],
                ['I\'m fine the way I am. More money would make me feel uncomfortable', 'monk'],
                ['To have someone else pay my bills so I can spend the whole paycheck!', 'spender'],
            ]],
            ['Here\'s how I feel about investing…', [
                ['I always let my dividends compound to maximise my return', 'amasser'],
                ['If I were to invest, I\'d want someone else to make all the decisions for me', 'avoider'],
                ['I invest only in safe, conservative choices like fixed deposit accounts', 'hoarder'],
                ['I\'ve always wanted to try something wild that might end up making me rich', 'spender'],
                ['If I were to invest, I would choose only socially responsible companies', 'monk'],
            ]],
            ['When I really want to buy something that\'s not in my budget:', [
                ['What budget? Everything will work out right', 'avoider'],
                ['I have to think hard before giving myself permission to spend the money', 'hoarder'],
                ['I\'ll buy it whether or not I can afford it', 'spender'],
                ['Most of the things I want aren\'t expensive, so I can afford them (even if I later wish I hadn\'t)', 'monk'],
                ['If it\'s important enough, I\'ll tweak my portfolio. Otherwise, I\'ll forget about it', 'amasser'],
            ]],
            ['When I think about money in general, to me it represents…', [
                ['Security', 'hoarder'],
                ['Happiness, pleasure, and excitement', 'spender'],
                ['A sense of greed and possibly corruption', 'monk'],
                ['A source of anxiety and conflict', 'avoider'],
                ['Power, prestige, and freedom', 'amasser'],
            ]],
            ['I would apply for a bank loan under these circumstances:', [
                ['To go on vacation or buy something I really wanted', 'spender'],
                ['Only if it were a dire emergency. I hope I\'ll never have to borrow money', 'monk'],
                ['To invest in a business or some higher-yielding opportunity', 'amasser'],
                ['To make essential repairs, pay for school fees, or increase my future security', 'hoarder'],
                ['I don\'t know', 'avoider'],
            ]],
            ['I worry about money…', [
                ['Never. I worry about more important things, like global warming', 'monk'],
                ['Somewhat, but I\'m doing all I can to make sure I\'ll have more than enough', 'amasser'],
                ['Constantly. It\'s the main thing I worry about', 'hoarder'],
                ['Only when a financial crisis strikes', 'avoider'],
                ['What, me worry? I just enjoy spending it!', 'spender'],
            ]],
            ['Here\'s how I feel about providing for my future:', [
                ['I\'m quite concerned, since it\'s been so hard for me to save', 'spender'],
                ['All I can do is hope the future will take care of itself', 'avoider'],
                ['Since I\'m planning to have plenty of money, the future will probably be fine', 'amasser'],
                ['I feel reasonably confident, since I\'ve been saving systematically for years', 'hoarder'],
                ['I think making a difference with one\'s life is much more important than money', 'monk'],
            ]],
            ['If I won a hundred million shillings, my first reaction would be to…', [
                ['Feel guilty, thinking about people who have nothing', 'monk'],
                ['Feel relieved that my future was now secure', 'hoarder'],
                ['Be totally overwhelmed. I would have no idea how to handle it', 'avoider'],
                ['Start thinking about ways to make it grow and use it for my own enjoyment', 'amasser'],
                ['Be wildly excited, realising that from now on I could buy anything I wanted', 'spender'],
            ]],
        ];

        foreach ($questions as $i => [$prompt, $opts]) {
            $letters = ['a', 'b', 'c', 'd', 'e'];
            $options = [];
            foreach ($opts as $j => [$label, $type]) {
                $options[] = ['key' => $letters[$j], 'emoji' => self::ICON[$type], 'label' => $label, 'type' => $type, 'points' => 0];
            }

            $assessment->allQuestions()->create([
                'section' => 'Money Personalities',
                'prompt' => $prompt,
                'type' => 'choice',
                'dimension' => null,
                'options' => $options,
                'sort' => $i,
                'is_active' => true,
            ]);
        }

        $bands = [
            [
                'dimension' => 'hoarder',
                'label' => 'The Hoarder', 'emoji' => 'shield-check', 'color' => '#1c2b5f',
                'headline' => 'Security is your love language, just don\'t let it become a cage.',
                'message' => 'You save, you budget, you sleep well because you planned well. Money means safety to you, and that discipline is genuinely rare. Your blind spot is enjoyment and growth: money parked "safely" quietly loses to inflation, and saying no to every treat can leave you, and the people you love, feeling deprived in a life you could actually afford.',
                'advice' => [
                    'Give yourself a guilt-free "enjoyment" line in your budget, spending it is part of the plan.',
                    'Move idle savings beyond the bank: a money market fund or investments so inflation doesn\'t erode them.',
                    'Run the Compound Growth tool to see what staying 100% "safe" costs you over 10 years.',
                ],
            ],
            [
                'dimension' => 'spender',
                'label' => 'The Spender', 'emoji' => 'sparkles', 'color' => '#58b9e6',
                'headline' => 'You know how to enjoy money, now teach it to stick around.',
                'message' => 'Money is happiness, generosity and living fully, and you\'re great at the living part. The world needs people who enjoy what they earn. Your blind spot is the future: when spending outpaces saving, one rough season can undo years of good ones, and debt creeps in quietly. The goal isn\'t to stop enjoying money, it\'s to enjoy it without borrowing from tomorrow.',
                'advice' => [
                    'Pay yourself first: automate savings on payday, before the fun money is available to spend.',
                    'Use a 24-hour rule on any non-essential buy, sleep on it, then decide.',
                    'Build your plan in the Budget Builder so every shilling has a job and the fun is guilt-free.',
                ],
            ],
            [
                'dimension' => 'monk',
                'label' => 'The Money Monk', 'emoji' => 'heart', 'color' => '#36498b',
                'headline' => 'Money isn\'t the opposite of your values, it can fund them.',
                'message' => 'You sense that money can corrupt, so you keep it at arm\'s length and give generously. That integrity is a gift. But the blind spot is real: money avoided is money that can\'t grow, and a monk who never builds security can become unable to help the very people and causes they care about. Wealth, in the right hands, yours, is simply fuel for good.',
                'advice' => [
                    'Reframe it: money is a tool for the impact you want, the more you steward, the more good you can do.',
                    'Invest in line with your values (ethical and socially responsible options exist and work).',
                    'Build a secure base so your generosity is sustainable, not a source of your own future strain.',
                ],
            ],
            [
                'dimension' => 'avoider',
                'label' => 'The Avoider', 'emoji' => 'compass', 'color' => '#2787b8',
                'headline' => 'Avoiding money doesn\'t make it go away, but simple beats perfect.',
                'message' => 'Money feels overwhelming, so you put off the budgeting, the records, the decisions, and hope it works out. You\'re far from alone. The blind spot is that avoidance quietly costs you: missed deadlines, late fees, no plan for emergencies, and a low hum of anxiety. The fix isn\'t becoming a finance nerd overnight, it\'s a few simple systems that run without you.',
                'advice' => [
                    'Start with one small step today, the free Financial Health Check shows you exactly where you stand.',
                    'Automate everything: savings, bills and contributions move on their own so you don\'t have to decide monthly.',
                    'Set up your numbers once in the Budget Builder, then just glance at it, clarity kills the dread.',
                ],
            ],
            [
                'dimension' => 'amasser',
                'label' => 'The Amasser', 'emoji' => 'trending-up', 'color' => '#1d5a7b',
                'headline' => 'You\'re built to grow money, make sure it\'s growing a life too.',
                'message' => 'Money is power, freedom and a scoreboard, and you play to win, investing, compounding, always moving it forward. That drive builds real wealth. Your blind spot is "enough": when net worth becomes the measure, it\'s easy to overwork, over-risk, and sideline rest, relationships and meaning. The wealthiest amassers decide what the money is FOR before chasing more of it.',
                'advice' => [
                    'Define your "enough" number and what the money is ultimately for, then invest toward that, not infinity.',
                    'Protect the base: keep a secure, untouchable cushion so a bold bet can never wipe you out.',
                    'Budget time and money for relationships, giving and rest, returns you can\'t measure on a statement.',
                ],
            ],
        ];

        foreach ($bands as $i => $band) {
            $assessment->bands()->create([...$band, 'min_percent' => 0, 'max_percent' => 100, 'sort' => $i]);
        }
    }
}
