<?php

namespace Database\Seeders;

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

/**
 * PublishingPagesSeeder
 *
 * Seeds the three required publishing pages for the footer:
 * - Privacy Policy (slug: privacy-policy)
 * - Terms of Service (slug: terms-of-service)
 * - Support (slug: support)
 *
 * Uses updateOrCreate for idempotency — safe to run multiple times.
 *
 * Requirements: 9.1, 9.2, 9.3, 9.4, 9.5
 */
class PublishingPagesSeeder extends Seeder
{
    public function run(): void
    {
        $pages = [
            $this->privacyPolicy(),
            $this->termsOfService(),
            $this->support(),
        ];

        foreach ($pages as $page) {
            PublishingPage::updateOrCreate(
                ['slug' => $page['slug']],
                $page
            );
        }
    }

    private function privacyPolicy(): array
    {
        return [
            'title'          => 'Privacy Policy',
            'slug'           => 'privacy-policy',
            'is_published'   => true,
            'published_at'   => now(),
            'layout'         => 'boxed',
            'show_breadcrumbs' => true,
            'show_sidebar'   => false,
            'seo_meta'       => [
                'meta_title'       => 'Privacy Policy — SSHIA',
                'meta_description' => 'Learn how SSHIA collects, uses, and protects your personal data.',
            ],
            'content_blocks' => [
                [
                    'type'     => 'hero',
                    'title'    => 'Privacy Policy',
                    'subtitle' => 'Last updated: ' . date('F Y'),
                ],
                [
                    'type'    => 'text',
                    'heading' => 'Data Collection',
                    'body'    => 'We collect personal information you provide when registering, such as your name, email address, phone number, and professional credentials. We also collect usage data automatically, including IP addresses, browser type, and pages visited, to improve our services.',
                ],
                [
                    'type'    => 'text',
                    'heading' => 'Data Usage',
                    'body'    => 'Your data is used to provide and improve our platform services, communicate important updates, process payments, and comply with legal obligations. We do not sell your personal information to third parties.',
                ],
                [
                    'type'    => 'text',
                    'heading' => 'Data Storage & Security',
                    'body'    => 'All data is stored on secure servers with industry-standard encryption. We retain your data for as long as your account is active or as required by law. You may request deletion of your account and associated data at any time.',
                ],
                [
                    'type'    => 'text',
                    'heading' => 'Your Rights',
                    'body'    => 'You have the right to access, correct, or delete your personal data. You may also object to processing, request data portability, or withdraw consent at any time. To exercise these rights, contact us using the details below.',
                ],
                [
                    'type'    => 'text',
                    'heading' => 'Contact Information',
                    'body'    => 'For privacy-related inquiries, please contact our Data Protection Officer via the Support page or email us directly. We will respond to all requests within 30 days.',
                ],
            ],
        ];
    }

    private function termsOfService(): array
    {
        return [
            'title'          => 'Terms of Service',
            'slug'           => 'terms-of-service',
            'is_published'   => true,
            'published_at'   => now(),
            'layout'         => 'boxed',
            'show_breadcrumbs' => true,
            'show_sidebar'   => false,
            'seo_meta'       => [
                'meta_title'       => 'Terms of Service — SSHIA',
                'meta_description' => 'Read the terms and conditions governing your use of the SSHIA platform.',
            ],
            'content_blocks' => [
                [
                    'type'     => 'hero',
                    'title'    => 'Terms of Service',
                    'subtitle' => 'Effective date: ' . date('F Y'),
                ],
                [
                    'type'    => 'text',
                    'heading' => 'Acceptance of Terms',
                    'body'    => 'By accessing or using the SSHIA platform, you agree to be bound by these Terms of Service and all applicable laws and regulations. If you do not agree with any of these terms, you are prohibited from using this platform.',
                ],
                [
                    'type'    => 'text',
                    'heading' => 'User Obligations',
                    'body'    => 'You are responsible for maintaining the confidentiality of your account credentials and for all activities that occur under your account. You agree to provide accurate, current, and complete information during registration and to update such information to keep it accurate.',
                ],
                [
                    'type'    => 'text',
                    'heading' => 'Prohibited Activities',
                    'body'    => 'You may not use the platform to: (a) violate any applicable laws or regulations; (b) transmit harmful, offensive, or misleading content; (c) attempt to gain unauthorized access to any part of the platform; (d) interfere with or disrupt the integrity or performance of the platform.',
                ],
                [
                    'type'    => 'text',
                    'heading' => 'Termination',
                    'body'    => 'We reserve the right to suspend or terminate your account at our sole discretion, without notice, for conduct that we believe violates these Terms of Service or is harmful to other users, us, or third parties. Upon termination, your right to use the platform will immediately cease.',
                ],
                [
                    'type'    => 'text',
                    'heading' => 'Changes to Terms',
                    'body'    => 'We reserve the right to modify these terms at any time. We will notify users of significant changes via email or a prominent notice on the platform. Continued use of the platform after changes constitutes acceptance of the new terms.',
                ],
            ],
        ];
    }

    private function support(): array
    {
        return [
            'title'          => 'Support',
            'slug'           => 'support',
            'is_published'   => true,
            'published_at'   => now(),
            'layout'         => 'boxed',
            'show_breadcrumbs' => true,
            'show_sidebar'   => false,
            'seo_meta'       => [
                'meta_title'       => 'Support — SSHIA',
                'meta_description' => 'Get help with the SSHIA platform. Contact us or browse our FAQ.',
            ],
            'content_blocks' => [
                [
                    'type'     => 'hero',
                    'title'    => 'Support Centre',
                    'subtitle' => 'We\'re here to help. Reach out or browse the FAQ below.',
                ],
                [
                    'type'    => 'text',
                    'heading' => 'Contact Information',
                    'body'    => 'For general enquiries and technical support, please use the following channels. Our support team is available Monday to Friday, 8:00 AM – 5:00 PM.',
                ],
                [
                    'type'  => 'cta',
                    'label' => 'Email Support',
                    'value' => 'support@sshia.org',
                    'icon'  => 'fa-envelope',
                ],
                [
                    'type'  => 'cta',
                    'label' => 'Hotline',
                    'value' => '+256 (0) 800 000 000',
                    'icon'  => 'fa-phone',
                ],
                [
                    'type'  => 'accordion',
                    'heading' => 'Frequently Asked Questions',
                    'items' => [
                        [
                            'question' => 'How do I reset my password?',
                            'answer'   => 'Click "Forgot Password" on the login page and enter your registered email address. You will receive a reset link within a few minutes.',
                        ],
                        [
                            'question' => 'How do I update my profile information?',
                            'answer'   => 'Log in and navigate to your profile via the top-right avatar menu. Click "Edit Profile" to update your personal and role-specific details.',
                        ],
                        [
                            'question' => 'How do I register for a training session?',
                            'answer'   => 'Navigate to the Training section from the main menu, browse available packages and sessions, then click "Register" on the session you wish to attend.',
                        ],
                        [
                            'question' => 'Who do I contact for membership-related issues?',
                            'answer'   => 'For membership enquiries, please submit a support ticket using the button below or call our hotline during business hours.',
                        ],
                    ],
                ],
                [
                    'type'    => 'cta',
                    'heading' => 'Submit a Support Ticket',
                    'body'    => 'Can\'t find what you\'re looking for? Submit a ticket and our team will get back to you within 1 business day.',
                    'label'   => 'Open a Ticket',
                    'url'     => '/tickets/create',
                    'icon'    => 'fa-ticket-alt',
                ],
            ],
        ];
    }
}
