<?php

declare(strict_types=1);

namespace App\Services\TrustDirectory;

use App\Models\ReviewedWebsite;
use App\Models\ReviewedWebsiteReview;

/**
 * Placeholder tokens: {siteName}, {domainBit} (include leading space + parens when non-empty).
 */
final class IndustryReviewPhraseBook
{
    /**
     * Opening sentences for generated community reviews, keyed by industry and user verdict.
     *
     * @return list<string>
     */
    public static function leadTemplates(string $industry, string $verdict): array
    {
        $industry = ReviewedWebsite::normalizeIndustry($industry);

        $byIndustry = self::templatesByIndustry();

        $specific = $byIndustry[$industry][$verdict] ?? null;
        if (is_array($specific) && $specific !== []) {
            return $specific;
        }

        return $byIndustry[ReviewedWebsite::INDUSTRY_GENERAL][$verdict]
            ?? $byIndustry[ReviewedWebsite::INDUSTRY_GENERAL][ReviewedWebsiteReview::VERDICT_UNSURE];
    }

    /**
     * @return array<string, array<string, list<string>>>
     */
    private static function templatesByIndustry(): array
    {
        $g = self::generalTemplates();

        return [
            ReviewedWebsite::INDUSTRY_GENERAL => $g,
            ReviewedWebsite::INDUSTRY_FINTECH => [
                ReviewedWebsiteReview::VERDICT_SCAM => [
                    'I wired funds through {siteName}{domainBit} and the payment never settled—support stopped replying after I sent the receipt.',
                    '{siteName} showed a clean dashboard but duplicate charges hit my card and disputes went nowhere.',
                    'Their “instant payout” promise was fake; my transfer sat pending for weeks with no real escalation path.',
                    'Fees looked low until hidden FX spreads and service charges appeared on the invoice.',
                ],
                ReviewedWebsiteReview::VERDICT_LEGIT => [
                    'Onboarding was straightforward and KYC completed in one session; payouts to my bank have been on time.',
                    '{siteName}{domainBit} handles recurring billing cleanly—statements and receipts match what I see in the app.',
                    'I use them for vendor payments; ACH and card settlements have been predictable with clear fee breakdowns.',
                    'Support answered a disputed charge quickly and reversed it after reviewing the ledger—felt like a real fintech operation.',
                ],
                ReviewedWebsiteReview::VERDICT_UNSURE => [
                    'Small transfers through {siteName}{domainBit} worked; I have not tried larger settlement volumes yet.',
                    'The product looks polished but I am waiting to see how they handle chargebacks and reconciliation long term.',
                    'Mixed experience—dashboard is nice, but settlement timing varied between payment rails.',
                ],
            ],
            ReviewedWebsite::INDUSTRY_BANKING => [
                ReviewedWebsiteReview::VERDICT_SCAM => [
                    'They asked for my online banking password “to verify the account”—major red flag; real banks never do that.',
                    '{siteName}{domainBit} sent a fake wire confirmation; my branch could not find any incoming transfer.',
                    'After I linked accounts, unauthorized debits started—treat this like a phishing operation.',
                    'Promised CD rates that do not exist on any regulated schedule; paperwork looked copied from a real bank.',
                ],
                ReviewedWebsiteReview::VERDICT_LEGIT => [
                    'Branch and app experience matched what FDIC disclosures said; wire transfers posted same day.',
                    '{siteName} opened my account with clear fee schedules and paper statements on request.',
                    'Loan docs matched the rate lock; no surprise items on the closing statement.',
                    'Fraud alerts triggered on a gas-station test charge and I confirmed it in seconds—solid retail banking UX.',
                ],
                ReviewedWebsiteReview::VERDICT_UNSURE => [
                    'Checking works fine for daily use; I have not tested mortgage or business products yet.',
                    '{siteName}{domainBit} feels legit but savings APY marketing was confusing—read the fine print.',
                    'Customer service was helpful once, slow another time; still deciding if I keep direct deposit there.',
                ],
            ],
            ReviewedWebsite::INDUSTRY_CRYPTO => [
                ReviewedWebsiteReview::VERDICT_SCAM => [
                    'Deposited crypto to {siteName}{domainBit} and withdrawals were disabled with endless “manual review.”',
                    'They pushed a fake token contract; my wallet drained after I approved a malicious approval.',
                    'Support on Telegram asked for my seed phrase—obvious scam impersonating the brand.',
                    'Trading looked real until withdrawal fees spiked and balances stopped matching the block explorer.',
                ],
                ReviewedWebsiteReview::VERDICT_LEGIT => [
                    'Withdrawals to self-custody completed in minutes; on-chain tx matched the explorer.',
                    '{siteName}{domainBit} 2FA and allowlists give me confidence for routine spot trades.',
                    'Staking rewards matched the advertised APR range after fees; dashboard shows epoch payouts clearly.',
                    'I moved a test amount first, then larger size—order book depth and fills behaved normally.',
                ],
                ReviewedWebsiteReview::VERDICT_UNSURE => [
                    'Small swaps worked; I have not stress-tested limits during high volatility.',
                    '{siteName} UI is fine but I still split holdings between here and cold storage.',
                    'On-ramp worked once; waiting to see how they handle a failed bank transfer reversal.',
                ],
            ],
            ReviewedWebsite::INDUSTRY_HOSPITALITY => [
                ReviewedWebsiteReview::VERDICT_SCAM => [
                    'Paid {siteName}{domainBit} for a “confirmed” villa and arrived to a closed property—no refund.',
                    'Reservation number was fake; the hotel had never heard of this booking site.',
                    'They double-charged my card and the cancellation policy was impossible to find until after payment.',
                    'Photos were from another property entirely; support ghosted when I asked for proof of partnership.',
                ],
                ReviewedWebsiteReview::VERDICT_LEGIT => [
                    'Check-in was seamless; room matched the photos and breakfast was included as listed.',
                    '{siteName}{domainBit} handled a date change without fees when the hotel allowed it—good coordination.',
                    'Concierge follow-up after checkout was a nice touch; invoice matched the quote.',
                    'Loyalty nights posted correctly and the front desk had my preferences on file.',
                ],
                ReviewedWebsiteReview::VERDICT_UNSURE => [
                    'Stay was fine but one amenity was closed without notice—worth asking before you book.',
                    '{siteName} pricing was OK; I always call the property directly to double-check now.',
                    'Mixed—great location, thin walls; depends what you prioritize.',
                ],
            ],
            ReviewedWebsite::INDUSTRY_ECOMMERCE => $g,
            ReviewedWebsite::INDUSTRY_TRAVEL => [
                ReviewedWebsiteReview::VERDICT_SCAM => [
                    'Ticketed through {siteName}{domainBit} and the airline had no record—money gone.',
                    'Baggage fees at checkout were hidden until after payment; total was hundreds more than advertised.',
                    'Fake “free cancellation” until I read page twelve; voucher instead of cash refund.',
                    'Car rental showed a luxury class image but I got a compact with no recourse.',
                ],
                ReviewedWebsiteReview::VERDICT_LEGIT => [
                    'Itinerary and seat assignments synced to the carrier app without issues.',
                    '{siteName}{domainBit} rebooked me quickly when a storm canceled the first leg—clear email trail.',
                    'Bundle saved money versus booking flight and hotel separately; vouchers arrived in inbox.',
                    'Travel insurance add-on paid a documented claim when luggage was delayed.',
                ],
                ReviewedWebsiteReview::VERDICT_UNSURE => [
                    'Flight was fine; hotel was more “budget” than photos suggested.',
                    '{siteName} worked for domestic hops; not sure I would trust them for multi-country complexity.',
                    'Prices jumped at checkout once due to taxes—annoying but not dishonest if you read totals.',
                ],
            ],
            ReviewedWebsite::INDUSTRY_GAMING => [
                ReviewedWebsiteReview::VERDICT_SCAM => [
                    'Bought currency on {siteName}{domainBit} and inventory never arrived—chat bots only.',
                    'Account banned right after a big win with no appeal process—feels rigged.',
                    'They sell “rare skins” that get revoked as stolen goods days later.',
                    'Loot box odds were nothing like marketing; refunds denied in fine print.',
                ],
                ReviewedWebsiteReview::VERDICT_LEGIT => [
                    'Matchmaking felt fair; purchases showed up instantly in inventory.',
                    '{siteName}{domainBit} moderation responded to a harassment report within a day.',
                    'Season pass content unlocked on schedule; no duplicate charges.',
                    'Community market prices were transparent; withdrawal to wallet worked.',
                ],
                ReviewedWebsiteReview::VERDICT_UNSURE => [
                    'Fun for casual play; monetization gets aggressive at higher ranks.',
                    '{siteName} servers lag sometimes—hard to tell if it is my connection or them.',
                    'Kids love it; parental controls could be clearer.',
                ],
            ],
            ReviewedWebsite::INDUSTRY_INSURANCE => [
                ReviewedWebsiteReview::VERDICT_SCAM => [
                    'Paid premiums to {siteName}{domainBit} for months; when I filed a claim they said policy did not exist.',
                    'Agent pressured bank transfer only—no proper policy documents ever arrived.',
                    'Quote was half of competitors because coverage exclusions were buried.',
                    'They spoofed a real insurer’s logo; state registry had no license match.',
                ],
                ReviewedWebsiteReview::VERDICT_LEGIT => [
                    'Claim adjuster inspected damage quickly and payment hit within the window they quoted.',
                    '{siteName}{domainBit} policy PDF matched the binder numbers I verified with the state.',
                    'Bundled auto and renters; discounts applied exactly as the calculator showed.',
                    'Customer service explained coverage limits clearly before I signed.',
                ],
                ReviewedWebsiteReview::VERDICT_UNSURE => [
                    'Renewal rate jumped; shopping around before I commit for another year.',
                    '{siteName} app is slick but I have not had to file a claim yet.',
                    'Mixed reviews online—my renewal was smooth so far.',
                ],
            ],
            ReviewedWebsite::INDUSTRY_REAL_ESTATE => [
                ReviewedWebsiteReview::VERDICT_SCAM => [
                    '{siteName}{domainBit} asked for an upfront wire to “hold” a listing that was not theirs.',
                    'Rental deposit taken on a cloned site; landlord never received it.',
                    'Promised guaranteed ROI on a development that does not exist on county records.',
                    'Pressure to skip inspection and escrow—classic investment scam pattern.',
                ],
                ReviewedWebsiteReview::VERDICT_LEGIT => [
                    'Agent showed comps transparently; offer and inspection timelines stayed on track.',
                    '{siteName}{domainBit} coordinated title and escrow cleanly; closing statement matched estimates.',
                    'Rental application fees were explained upfront; refund policy was in writing.',
                    'Virtual tour matched the in-person walkthrough—no bait and switch.',
                ],
                ReviewedWebsiteReview::VERDICT_UNSURE => [
                    'Search UX is good; still verifying how fresh listings are in my ZIP.',
                    '{siteName} mixed helpful listings with aggressive lead-gen calls.',
                    'One smooth lease renewal; another property had slow maintenance tickets.',
                ],
            ],
            ReviewedWebsite::INDUSTRY_SAAS => [
                ReviewedWebsiteReview::VERDICT_SCAM => [
                    'Signed up for {siteName}{domainBit}; after payment the product links 404 and billing kept charging.',
                    'Sales demo used a fake dataset—production export limits made the tool unusable.',
                    'They resold my workspace data according to a buried clause—check privacy terms.',
                    '“Lifetime deal” revoked after six months with a forced upgrade paywall.',
                ],
                ReviewedWebsiteReview::VERDICT_LEGIT => [
                    'Onboarding checklist and API docs matched reality; first integration shipped in a week.',
                    '{siteName}{domainBit} uptime dashboard matched our monitors; incidents were communicated quickly.',
                    'SOC2 report available on request; SSO and audit logs work as documented.',
                    'Support reproduced a bug, shipped a fix, and credited the month—professional B2B SaaS.',
                ],
                ReviewedWebsiteReview::VERDICT_UNSURE => [
                    'Core features solid; pricing jumps at the tier we need next quarter.',
                    '{siteName} UI improved but mobile still feels like an afterthought.',
                    'Good for small teams; unsure how it scales to hundreds of seats.',
                ],
            ],
        ];
    }

    /**
     * @return array<string, list<string>>
     */
    private static function generalTemplates(): array
    {
        return [
            ReviewedWebsiteReview::VERDICT_SCAM => [
                'I would stay away from {siteName}{domainBit}—too many red flags after I paid.',
                '{siteName} looked fine until support vanished. Not comfortable recommending them.',
                'Had a bad experience with {siteName}; charges did not match what was advertised.',
                'Search turned up {siteName}{domainBit}—wish I had read more warnings first.',
            ],
            ReviewedWebsiteReview::VERDICT_LEGIT => [
                'Used {siteName}{domainBit} twice—smooth checkout and delivery both times.',
                '{siteName} answered my questions quickly; felt like a real operation.',
                'Happy with {siteName}. Clear policies and what I ordered matched the site.',
                'I vetted {siteName} before buying; everything checked out and the order was fine.',
            ],
            ReviewedWebsiteReview::VERDICT_UNSURE => [
                'Mixed feelings about {siteName}{domainBit}—fine for small orders, unsure for bigger ones.',
                '{siteName} worked for me once; a friend had a slower experience.',
                'Still on the fence about {siteName}. Some things look good, some feel rushed.',
            ],
        ];
    }
}
