<?php

namespace Database\Seeders;

use App\Models\HelpCategory;
use App\Models\HelpArticle;
use App\Models\SupportChannel;
use App\Models\Offer;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class ConversionEngineSeeder extends Seeder
{
    public function run(): void
    {
        // 1. SUPPORT CHANNELS
        SupportChannel::create([
            'name' => 'Expert WhatsApp',
            'type' => 'whatsapp',
            'value' => '923001234567',
            'url_pattern' => 'https://wa.me/{val}',
            'sort_order' => 1,
        ]);

        SupportChannel::create([
            'name' => 'Telegram Support',
            'type' => 'telegram',
            'value' => 'texora_compliance',
            'url_pattern' => 'https://t.me/{val}',
            'sort_order' => 2,
        ]);

        // 2. OFFERS
        Offer::create([
            'title' => 'Free Tax Consultation',
            'description' => 'Talk to our senior compliance architects for 15 minutes for free. Expert guidance for 2024 filings.',
            'cta_text' => 'Grab Consultation',
            'whatsapp_message' => 'Hi Texora! I want to claim my FREE 15-min Tax Consultation.',
            'bg_gradient' => 'linear-gradient(135deg, #0A1628, #2563EB)',
            'show_logic' => 'random',
        ]);

        Offer::create([
            'title' => 'Save PKR 1,000 on NTN',
            'description' => 'Limited time offer for new founders. Get your NTN registered with a dedicated manager discount.',
            'cta_text' => 'Save Now',
            'whatsapp_message' => 'Hi! I want to claim the PKR 1,000 discount on my NTN registration.',
            'bg_gradient' => 'linear-gradient(135deg, #10B981, #0A1628)',
            'show_logic' => 'random',
        ]);

        // 3. HELP CATEGORIES & ARTICLES
        $categories = [
            'NTN & Basics' => [
                'How to Register NTN' => 'To register for an NTN in Pakistan, you need to visit the IRIS portal or use Texora. Required documents include CNIC and electricity bill.',
                'NTN for Freelancers' => 'Freelancers can register as individuals. You must provide a service proof or bank statement to verify your income source.',
                'Required Documents for NTN' => 'Individual: CNIC, Phone, Email, Electricity Bill. Business: Registration Docs, Rent Agreement.',
            ],
            'Tax Filing' => [
                'Tax Filing (Salaried Guide)' => 'Salaried individuals must file if their income exceeds PKR 600,000 annually. You need your salary slip and proof of investments for deductions.',
                'Common Tax Mistakes' => 'Avoid entering incorrect bank details or missing out on refundable tax from your electricity/phone bills.',
            ],
            'Company' => [
                'Company Registration Process' => 'The SECP process involves Name Reservation, Submission of MOA/AOA, and Payment of Filing Fees. Usually takes 3-5 days.',
                'AOP vs Company' => 'An Association of Persons (AOP) is easier to form but has unlimited liability. A Private Limited Company offers limited liability protection.',
            ]
        ];

        foreach ($categories as $catName => $articles) {
            $cat = HelpCategory::create([
                'name' => $catName,
                'slug' => Str::slug($catName),
                'icon' => match($catName) {
                    'NTN & Basics' => '🏢',
                    'Tax Filing' => '📊',
                    'Company' => '🏗️',
                    default => '📄'
                }
            ]);

            foreach ($articles as $title => $content) {
                HelpArticle::create([
                    'help_category_id' => $cat->id,
                    'title' => $title,
                    'slug' => Str::slug($title),
                    'content' => $content,
                    'excerpt' => Str::limit($content, 50),
                    'is_active' => true,
                ]);
            }
        }
    }
}
