<?php

namespace Database\Seeders;

use App\Models\Download;
use App\Models\Faq;
use App\Models\JobListing;
use App\Models\Media;
use App\Models\NewsCategory;
use App\Models\NewsPost;
use App\Models\Page;
use App\Models\PageSection;
use App\Models\Service;
use App\Models\Setting;
use App\Models\SiteStat;
use App\Models\TeamMember;
use App\Models\Testimonial;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;
class SiteContentSeeder extends Seeder
{
    public function run(): void
    {
        $this->seedSettings();
        $this->seedPages();
        $this->seedServices();
        $this->seedTeamMembers();
        $this->seedTestimonials();
        $this->seedFaqs();
        $this->seedSiteStats();
        $this->seedNews();
        $this->seedCareers();
        $this->seedDownloads();
        $this->seedHomeGalleryMedia();
    }

    protected function seedSettings(): void
    {
        $settings = Setting::current();
        $settings->fill([
            'site_name' => 'Hillcrest Living',
            'site_tagline' => 'Supported living for older adults aged 65+',
            'contact_email' => env('ADMIN_NOTIFICATION_EMAIL', 'support@hillcrestliving.co.uk'),
            'contact_phone' => '01234 567890',
            'contact_address' => "49 May Tree Close\nWaterthorpe\nSheffield\nSouth Yorkshire\nS20 7HB\nUnited Kingdom",
            'contact_map_embed_url' => 'https://www.google.com/maps?q=49+May+Tree+Close,+Waterthorpe,+Sheffield,+South+Yorkshire,+S20+7HB,+United+Kingdom&output=embed',
            'contact_map_place_label' => '49 May Tree Close, Waterthorpe, Sheffield (S20 7HB)',
            'contact_branches' => [
                [
                    'name' => 'Sheffield Branch',
                    'address' => "49 May Tree Close\nWaterthorpe\nSheffield\nSouth Yorkshire\nS20 7HB\nUnited Kingdom",
                    'phone' => '01234 567890',
                    'email' => env('ADMIN_NOTIFICATION_EMAIL', 'support@hillcrestliving.co.uk'),
                    'map_embed_url' => 'https://www.google.com/maps?q=49+May+Tree+Close,+Waterthorpe,+Sheffield,+South+Yorkshire,+S20+7HB,+United+Kingdom&output=embed',
                    'is_primary' => true,
                ],
            ],
            'footer_text' => 'Hillcrest Living is a registered trademark. Replace this text with governance and registration details.',
            'cookie_notice_enabled' => true,
            'cookie_notice_text' => 'We use essential cookies to operate this site and improve your experience. You can manage preferences in your browser settings.',
        ]);
        $settings->save();
    }

    protected function seedPages(): void
    {
        $home = Page::query()->updateOrCreate(
            ['route_path' => '/'],
            [
                'title' => 'Home',
                'slug' => 'home',
                'intro' => null,
                'status' => 'published',
                'published_at' => now(),
                'meta_title' => 'Supported living with independence and dignity',
                'meta_description' => 'Hillcrest Living provides supported living for older adults aged 65+.',
            ]
        );

        $heroSlides = [
            [
                'section_key' => 'hero',
                'sort_order' => 0,
                'heading' => 'Helping older adults live independently, safely, and with dignity',
                'body' => '<p>At Hillcrest Living, we provide supported living for older adults aged 65+ who want to maintain their independence while receiving the right level of day-to-day support. We focus on low to moderate support needs, creating a safe, comfortable, and empowering environment without intrusive care.</p>',
            ],
            [
                'section_key' => 'hero_slide',
                'sort_order' => 1,
                'heading' => 'Supported Living That Promotes Independence',
                'body' => '<p>Supported living is about having your own space, your own routine, and your own life, with the reassurance that support is available when needed. We help individuals stay in control, build confidence, and remain part of their community.</p>',
            ],
            [
                'section_key' => 'hero_slide',
                'sort_order' => 2,
                'heading' => 'Practical, non-intrusive support',
                'body' => '<p>We provide practical support including daily routine, medication prompting, shopping, errands, and social engagement. Our focus is helping individuals build confidence, routine, and independence.</p>',
            ],
        ];

        foreach ($heroSlides as $slide) {
            PageSection::query()->updateOrCreate(
                [
                    'page_id' => $home->id,
                    'section_key' => $slide['section_key'],
                    'sort_order' => $slide['sort_order'],
                ],
                [
                    'heading' => $slide['heading'],
                    'subheading' => null,
                    'body' => $slide['body'],
                    'cta_primary_label' => 'Make a Referral',
                    'cta_primary_url' => url('/referral'),
                    'cta_secondary_label' => 'Speak to Our Team',
                    'cta_secondary_url' => url('/contact'),
                    'rotation_interval_ms' => 6000,
                    'is_active' => true,
                ]
            );
        }

        PageSection::query()->updateOrCreate(
            [
                'page_id' => $home->id,
                'section_key' => 'welcome',
            ],
            [
                'heading' => 'Thoughtful support, without intruding',
                'subheading' => 'We specialise in lighter-touch support tailored to routines, wellbeing, and community connection.',
                'body' => '<p>This is placeholder content seeded for local development — replace via the Pages admin resource.</p>',
                'sort_order' => 10,
                'is_active' => true,
            ]
        );

        PageSection::query()->updateOrCreate(
            [
                'page_id' => $home->id,
                'section_key' => 'home_services',
            ],
            [
                'heading' => 'Our Support Services',
                'subheading' => 'Practical, non-intrusive support',
                'body' => '<p>We provide practical, non-intrusive support, including:</p>',
                'sort_order' => 20,
                'is_active' => true,
            ]
        );

        PageSection::query()->updateOrCreate(
            [
                'page_id' => $home->id,
                'section_key' => 'home_approach',
            ],
            [
                'heading' => 'Our Approach',
                'subheading' => 'Person-Centred. Respectful. Empowering.',
                'body' => '<p><strong>At Hillcrest, no two individuals are the same.</strong></p><p>We:</p><ul><li>build support plans around each person</li><li>respect independence and personal choice</li><li>encourage skill-building and confidence</li><li>create a calm, homely environment</li></ul><p>Supported living works best when people feel in control of their lives, not managed, and that is exactly how we operate.</p><h3>Accommodation</h3><p>Our supported living environments are:</p><ul><li>safe and comfortable</li><li>well-located within the community</li><li>designed to promote independence</li><li>close to local amenities and transport</li></ul><p>Residents have their own private space, shared or self-contained living options, and full control over their daily routines. Supported living typically allows individuals to live in their own tenancy while receiving support.</p>',
                'sort_order' => 30,
                'is_active' => true,
            ]
        );

        PageSection::query()->updateOrCreate(
            [
                'page_id' => $home->id,
                'section_key' => 'home_referrals',
            ],
            [
                'heading' => 'Referrals',
                'subheading' => 'Referrals made simple',
                'body' => '<p>We accept referrals from Local Authorities, Social Workers, Healthcare Professionals, and Families/private clients.</p><p>Our process is designed for fast response times, clear assessment steps, and smooth onboarding.</p>',
                'cta_primary_label' => 'Submit a Referral',
                'cta_primary_url' => url('/referral'),
                'sort_order' => 40,
                'is_active' => true,
            ]
        );

        PageSection::query()->updateOrCreate(
            [
                'page_id' => $home->id,
                'section_key' => 'home_why_choose',
            ],
            [
                'heading' => 'Why Choose Hillcrest',
                'subheading' => 'Why families choose us',
                'body' => '<ul><li>Focused on older adults aged 65+.</li><li>Clear model for low to moderate support needs.</li><li>Independence-first and culturally aware approach.</li><li>Flexible support designed for both families and professionals.</li></ul>',
                'cta_primary_label' => 'Get in Touch Today',
                'cta_primary_url' => url('/contact'),
                'sort_order' => 50,
                'is_active' => true,
            ]
        );

        PageSection::query()->updateOrCreate(
            [
                'page_id' => $home->id,
                'section_key' => 'home_testimonials',
            ],
            [
                'heading' => 'Trusted by families and professionals',
                'subheading' => 'Real experiences',
                'body' => '<p>Kind words from residents, families, and referral partners who value calm, respectful support.</p>',
                'sort_order' => 60,
                'is_active' => true,
            ]
        );

        PageSection::query()->updateOrCreate(
            [
                'page_id' => $home->id,
                'section_key' => 'home_faqs',
            ],
            [
                'heading' => 'Questions families often ask',
                'subheading' => 'Frequently asked questions',
                'body' => '<p>Helpful answers about referrals, accommodation, and how supported living works at Hillcrest.</p>',
                'sort_order' => 70,
                'is_active' => true,
            ]
        );

        $this->basicPage([
            'route_path' => '/services',
            'slug' => 'services',
            'title' => 'Our services',
            'meta_title' => 'Our supported living services',
            'intro' => 'Practical assistance that supports independence.',
        ]);

        $this->basicPage([
            'route_path' => '/news',
            'slug' => 'news',
            'title' => 'News',
            'meta_title' => 'News',
            'intro' => 'Updates from Hillcrest Living.',
        ]);

        $this->basicPage([
            'route_path' => '/careers',
            'slug' => 'careers',
            'title' => 'Careers',
            'meta_title' => 'Careers at Hillcrest Living',
            'intro' => 'Join a team that respects dignity and routine.',
        ]);

        $this->basicPage([
            'route_path' => '/downloads',
            'slug' => 'downloads',
            'title' => 'Downloads',
            'intro' => 'Useful guides and forms.',
        ]);

        $this->basicPage([
            'route_path' => '/contact',
            'slug' => 'contact',
            'title' => 'Contact',
            'meta_title' => 'Contact Hillcrest Living',
            'intro' => 'Speak to our team — we aim to reply within two working days.',
        ]);

        $this->basicPage([
            'route_path' => '/referral',
            'slug' => 'referral',
            'title' => 'Referral',
            'meta_title' => 'Secure referral pathway',
            'intro' => 'Use this secure form for professional referrals. For general enquiries please use Contact.',
        ]);

        $referralPage = Page::query()->where('route_path', '/referral')->first();
        if ($referralPage) {
            PageSection::query()->updateOrCreate(
                [
                    'page_id' => $referralPage->id,
                    'section_key' => 'referral_info',
                ],
                [
                    'heading' => 'What happens next?',
                    'subheading' => 'We acknowledge referrals promptly and prioritise safeguarding.',
                    'body' => '<p>An administrator will confirm receipt via email — adjust this copy in Pages.</p>',
                    'sort_order' => 0,
                    'is_active' => true,
                ]
            );
        }

        $this->basicPage([
            'route_path' => '/about',
            'slug' => 'about',
            'title' => 'About us',
            'meta_title' => 'About Hillcrest Living',
            'intro' => 'We believe calm environments and respectful support help people flourish.',
        ]);

        $this->basicPage([
            'route_path' => '/who-we-support',
            'slug' => 'who-we-support',
            'title' => 'Who we support',
            'meta_title' => 'Who Hillcrest Living supports',
            'intro' => 'We specialise in lighter-touch supported living — not intrusive personal care.',
        ]);

        $this->basicPage([
            'route_path' => '/testimonials',
            'slug' => 'testimonials',
            'title' => 'Testimonials',
            'meta_title' => 'Families and residents share their experience',
            'intro' => 'Kind words from residents, families, and referral partners.',
        ]);

        $this->basicPage([
            'route_path' => '/privacy',
            'slug' => 'privacy',
            'title' => 'Privacy',
            'meta_title' => 'Privacy notice',
            'intro' => 'Replace this seeded notice with solicitor‑reviewed wording before production.',
        ]);
    }

    /**
     * @param  array{route_path: string, slug: string, title: string, intro?: ?string, meta_title?: ?string}  $payload
     */
    protected function basicPage(array $payload): Page
    {
        return Page::query()->updateOrCreate(
            ['route_path' => $payload['route_path']],
            [
                'title' => $payload['title'],
                'slug' => $payload['slug'],
                'intro' => $payload['intro'] ?? null,
                'status' => 'published',
                'published_at' => now(),
                'meta_title' => $payload['meta_title'] ?? $payload['title'],
                'meta_description' => $payload['meta_description'] ?? null,
            ]
        );
    }

    protected function seedServices(): void
    {
        $items = [
            [
                'title' => 'Daily routine and wellbeing support',
                'slug' => 'daily-routine-support',
                'summary' => 'Gentle support with structuring each day and maintaining a healthy routine.',
                'sort_order' => 0,
            ],
            [
                'title' => 'Medication prompting (not administration)',
                'slug' => 'medication-prompting',
                'summary' => 'Prompting and reminders to help people stay on track with prescribed medication plans.',
                'sort_order' => 10,
            ],
            [
                'title' => 'Help with shopping and errands',
                'slug' => 'shopping-and-errands-support',
                'summary' => 'Practical support for shopping, collecting essentials, and everyday errands.',
                'sort_order' => 20,
            ],
            [
                'title' => 'Appointment support',
                'slug' => 'appointment-support',
                'summary' => 'Support to schedule, prepare for, and attend key health or community appointments.',
                'sort_order' => 30,
            ],
            [
                'title' => 'Light domestic support and organisation',
                'slug' => 'light-domestic-support-and-organisation',
                'summary' => 'Help with light home organisation to maintain a calm and comfortable living space.',
                'sort_order' => 40,
            ],
            [
                'title' => 'Social engagement and companionship',
                'slug' => 'social-engagement-and-companionship',
                'summary' => 'Regular social interaction and companionship to reduce isolation and improve wellbeing.',
                'sort_order' => 50,
            ],
            [
                'title' => 'Community access and activities',
                'slug' => 'community-access-and-activities',
                'summary' => 'Encouragement and support to access local activities, groups, and community resources.',
                'sort_order' => 60,
            ],
            [
                'title' => 'Budgeting and basic life admin support',
                'slug' => 'budgeting-and-basic-life-admin-support',
                'summary' => 'Support with budgeting basics, reminders, and light life administration tasks.',
                'sort_order' => 70,
            ],
        ];

        foreach ($items as $item) {
            Service::query()->updateOrCreate(
                ['slug' => $item['slug']],
                [
                    'title' => $item['title'],
                    'summary' => $item['summary'],
                    'body' => '<p>'.$item['summary'].' Replace with fuller copy in Filament.</p>',
                    'is_published' => true,
                    'sort_order' => $item['sort_order'],
                ]
            );
        }
    }

    protected function seedTeamMembers(): void
    {
        foreach ([
            ['name' => 'Alex Mercer', 'role_title' => 'Registered Manager', 'sort_order' => 0],
            ['name' => 'Sam Rivera', 'role_title' => 'Support Coordinator', 'sort_order' => 10],
        ] as $row) {
            TeamMember::query()->updateOrCreate(
                ['name' => $row['name']],
                [
                    'role_title' => $row['role_title'],
                    'bio' => '<p>This is seeded biography — replace via Team members admin.</p>',
                    'sort_order' => $row['sort_order'],
                    'is_published' => true,
                ]
            );
        }
    }

    protected function seedTestimonials(): void
    {
        $rows = [
            ['quote' => 'The team respect routine and never rush us — it feels like home.', 'author_name' => 'Family member', 'source_type' => 'family', 'is_featured' => true, 'sort_order' => 0],
            ['quote' => 'I still choose when to go out and what to wear — Hillcrest quietly supports.', 'author_name' => 'Resident', 'source_type' => 'resident', 'is_featured' => true, 'sort_order' => 10],
            ['quote' => 'Communication is clear, compassionate, and professional. The referral process felt calm from the start.', 'author_name' => 'Social worker', 'source_type' => 'referrer', 'is_featured' => true, 'sort_order' => 20],
            ['quote' => 'Hillcrest helped my mum keep her independence while giving us confidence that support is nearby.', 'author_name' => 'Daughter of resident', 'source_type' => 'family', 'is_featured' => true, 'sort_order' => 30],
            ['quote' => 'The support is respectful and practical. It encourages routine without taking over.', 'author_name' => 'Family member', 'source_type' => 'family', 'is_featured' => true, 'sort_order' => 40],
            ['quote' => 'Responsive, professional, compassionate — referrals are handled calmly.', 'author_name' => 'Referrer', 'source_type' => 'referrer', 'is_featured' => false, 'sort_order' => 50],
        ];

        foreach ($rows as $row) {
            Testimonial::query()->updateOrCreate(
                ['quote' => $row['quote']],
                [
                    'author_name' => $row['author_name'],
                    'source_type' => $row['source_type'],
                    'star_rating' => 5,
                    'is_featured' => $row['is_featured'],
                    'is_published' => true,
                    'sort_order' => $row['sort_order'],
                ]
            );
        }
    }

    protected function seedFaqs(): void
    {
        $rows = [
            [
                'question' => 'Who is Hillcrest Living suitable for?',
                'answer' => '<p>Hillcrest supports older adults aged 65+ who value independence but need low to moderate day-to-day support to live safely and confidently.</p>',
                'category' => 'Who we support',
                'sort_order' => 0,
            ],
            [
                'question' => 'Do you provide personal care?',
                'answer' => '<p>Our model focuses on practical, non-intrusive supported living. We can prompt, encourage, and support routines, but personal care needs should be discussed during assessment.</p>',
                'category' => 'Support',
                'sort_order' => 10,
            ],
            [
                'question' => 'Who can make a referral?',
                'answer' => '<p>We accept referrals from Local Authorities, Social Workers, Healthcare Professionals, families, and private clients.</p>',
                'category' => 'Referrals',
                'sort_order' => 20,
            ],
            [
                'question' => 'What accommodation options are available?',
                'answer' => '<p>Residents may have private space with shared or self-contained living options, depending on availability and assessed needs.</p>',
                'category' => 'Accommodation',
                'sort_order' => 30,
            ],
            [
                'question' => 'How quickly do you respond to enquiries?',
                'answer' => '<p>We aim to respond promptly, explain the next steps clearly, and arrange assessment conversations where appropriate.</p>',
                'category' => 'Referrals',
                'sort_order' => 40,
            ],
        ];

        foreach ($rows as $row) {
            Faq::query()->updateOrCreate(
                ['question' => $row['question']],
                [
                    'answer' => $row['answer'],
                    'category' => $row['category'],
                    'sort_order' => $row['sort_order'],
                    'is_published' => true,
                ]
            );
        }
    }

    protected function seedSiteStats(): void
    {
        foreach ([
            ['label' => 'Residents supported weekly', 'value_number' => 120, 'suffix' => '+', 'sort_order' => 0],
            ['label' => 'Families supported', 'value_number' => 85, 'suffix' => '+', 'sort_order' => 10],
            ['label' => 'Average response time', 'value_text' => 'Under', 'suffix' => '24h', 'sort_order' => 20],
        ] as $row) {
            SiteStat::query()->updateOrCreate(
                ['label' => $row['label']],
                [
                    'value_number' => $row['value_number'] ?? null,
                    'value_text' => $row['value_text'] ?? null,
                    'suffix' => $row['suffix'] ?? null,
                    'sort_order' => $row['sort_order'],
                    'is_published' => true,
                ]
            );
        }
    }

    protected function seedNews(): void
    {
        $updates = NewsCategory::query()->firstOrCreate(['slug' => 'updates'], ['name' => 'Updates']);
        $sector = NewsCategory::query()->firstOrCreate(['slug' => 'sector-insights'], ['name' => 'Sector insights']);
        $guidance = NewsCategory::query()->firstOrCreate(['slug' => 'guidance'], ['name' => 'Guidance']);

        $coverImages = [
            'welcome-to-the-new-site' => Media::query()->where('path', 'home-gallery/hillcrest-community-photo.png')->first(),
            'supported-living-and-independence' => Media::query()->where('path', 'home-gallery/hillcrest-about-story.png')->first(),
            'uk-supported-living-demand' => Media::query()->where('path', 'home-gallery/faq-accommodation-support.png')->first(),
            'questions-to-ask-before-a-referral' => Media::query()->where('path', 'home-gallery/faq-support-conversation.png')->first(),
            'choosing-low-to-moderate-support' => Media::query()->where('path', 'home-gallery/hillcrest-gallery-photo-1.png')->first(),
        ];

        $posts = [
            [
                'slug' => 'welcome-to-the-new-site',
                'title' => 'Welcome to the refreshed Hillcrest site',
                'excerpt' => 'We rebuilt our presence to explain who we serve and why routine, dignity, and independence matter.',
                'body' => '<p>Our refreshed website has been designed to make it easier for families, professionals, and older adults to understand the Hillcrest Living model.</p><p>We focus on supported living for older adults aged 65+ who value independence but may benefit from structured, day-to-day support.</p>',
                'category_id' => $updates->id,
                'published_at' => now()->subDays(2),
            ],
            [
                'slug' => 'supported-living-and-independence',
                'title' => 'Why supported living is centred on independence',
                'excerpt' => 'Supported living is most effective when people remain in control of daily choices, routines, and personal goals.',
                'body' => '<p>Across the UK, supported living continues to be valued as an alternative to more institutional care settings because it keeps choice, routine, and personal autonomy at the centre.</p><p>At Hillcrest Living, our approach is simple: support should be practical, respectful, and designed around the individual.</p><ul><li>Support plans should reflect personal routines.</li><li>Accommodation should feel safe and homely.</li><li>People should be encouraged to remain connected to their community.</li></ul>',
                'category_id' => $guidance->id,
                'published_at' => now()->subDays(8),
            ],
            [
                'slug' => 'uk-supported-living-demand',
                'title' => 'UK councils continue to invest in supported living options',
                'excerpt' => 'Recent council-backed projects show continued demand for community-based supported living accommodation across the UK.',
                'body' => '<p>Supported living remains a significant focus across the UK as local authorities look for more flexible, community-based accommodation options.</p><p>Recent sector updates have highlighted new supported living schemes, council investment, and growing attention on quality, oversight, and resident choice.</p><p>For older adults and families, this reinforces the importance of choosing services that are transparent, person-centred, and clear about the level of support offered.</p>',
                'category_id' => $sector->id,
                'published_at' => now()->subDays(14),
            ],
            [
                'slug' => 'questions-to-ask-before-a-referral',
                'title' => 'Questions to ask before making a supported living referral',
                'excerpt' => 'A clear referral conversation helps identify the right level of support and whether supported living is suitable.',
                'body' => '<p>Before making a referral, it helps to gather a clear picture of the individual’s current routine, support needs, preferences, and desired outcomes.</p><h3>Helpful questions include:</h3><ul><li>What support is needed day to day?</li><li>Is the person mostly independent?</li><li>Would regular prompting, companionship, or routine support help?</li><li>Are there risks around isolation, appointments, or medication prompting?</li></ul><p>Hillcrest welcomes conversations from families and professionals who want to understand suitability before starting a formal referral.</p>',
                'category_id' => $guidance->id,
                'published_at' => now()->subDays(21),
            ],
            [
                'slug' => 'choosing-low-to-moderate-support',
                'title' => 'Understanding low to moderate support needs',
                'excerpt' => 'Low to moderate support can help older adults maintain independence without intrusive care.',
                'body' => '<p>Low to moderate support may include routine building, medication prompting, light domestic support, errands, appointments, social engagement, and community access.</p><p>This type of support is especially helpful for older adults who do not need intensive personal care but benefit from structure, reassurance, and regular contact.</p>',
                'category_id' => $guidance->id,
                'published_at' => now()->subDays(28),
            ],
        ];

        foreach ($posts as $post) {
            NewsPost::query()->updateOrCreate(
                ['slug' => $post['slug']],
                [
                    'title' => $post['title'],
                    'excerpt' => $post['excerpt'],
                    'body' => $post['body'],
                    'category_id' => $post['category_id'],
                    'cover_media_id' => $coverImages[$post['slug']]?->id,
                    'status' => 'published',
                    'published_at' => $post['published_at'],
                    'meta_title' => $post['title'],
                    'meta_description' => $post['excerpt'],
                ]
            );
        }
    }

    protected function seedCareers(): void
    {
        $roles = [
            [
                'slug' => 'senior-support-worker',
                'title' => 'Senior Support Worker',
                'department' => 'Care Operations',
                'location' => 'Sheffield & South Yorkshire',
                'employment_type' => 'full_time',
                'salary_text' => null,
                'description' => '<p><strong>Role overview</strong></p><p>We are recruiting a Senior Support Worker to help lead safe, person-centred supported living services for older adults. You will provide direct support while mentoring frontline staff and maintaining high safeguarding standards.</p><p><strong>Key responsibilities</strong></p><ul><li>Deliver and supervise high-quality daily support plans.</li><li>Promote independence, dignity, and choice for each resident.</li><li>Maintain accurate care documentation and incident reporting.</li><li>Support medication prompting processes in line with policy.</li><li>Escalate safeguarding concerns promptly and appropriately.</li></ul><p><strong>Essential criteria</strong></p><ul><li>Previous UK health and social care experience.</li><li>Level 3 Diploma in Adult Care (or willingness to work toward it).</li><li>Good written and verbal communication skills.</li><li>Understanding of safeguarding and Mental Capacity principles.</li></ul><p><strong>Compliance</strong></p><p>Appointment is subject to enhanced DBS, satisfactory references, and Right to Work checks.</p>',
                'closing_date' => now()->addMonths(2)->toDateString(),
            ],
            [
                'slug' => 'care-support-worker',
                'title' => 'Care Support Worker',
                'department' => 'Frontline Care',
                'location' => 'Sheffield',
                'employment_type' => 'full_time',
                'salary_text' => null,
                'description' => '<p><strong>Role overview</strong></p><p>As a Care Support Worker, you will provide practical, respectful support that enables residents to live safely and independently in their own supported living environment.</p><p><strong>Key responsibilities</strong></p><ul><li>Support routines, wellbeing, and social engagement activities.</li><li>Assist with appointments, shopping, and community access.</li><li>Provide companionship and monitor day-to-day wellbeing.</li><li>Keep clear, timely records aligned to service standards.</li><li>Work collaboratively with colleagues, families, and professionals.</li></ul><p><strong>Essential criteria</strong></p><ul><li>Compassionate, professional, and reliable approach.</li><li>Ability to work shifts, including evenings/weekends where required.</li><li>Good communication and teamwork skills.</li><li>Previous UK care experience desirable but not essential.</li></ul><p><strong>Compliance</strong></p><p>All roles are subject to enhanced DBS, pre-employment checks, and safer recruitment procedures.</p>',
                'closing_date' => now()->addMonths(1)->toDateString(),
            ],
            [
                'slug' => 'registered-care-manager',
                'title' => 'Registered Care Manager',
                'department' => 'Leadership',
                'location' => 'South Yorkshire',
                'employment_type' => 'full_time',
                'salary_text' => null,
                'description' => '<p><strong>Role overview</strong></p><p>We are seeking a Registered Care Manager to lead operational quality and governance across our supported living services, ensuring compliance with CQC expectations and internal quality frameworks.</p><p><strong>Key responsibilities</strong></p><ul><li>Lead service quality, audits, and continuous improvement plans.</li><li>Ensure robust safeguarding and risk management systems.</li><li>Oversee staffing, supervision, training, and performance standards.</li><li>Maintain compliance with CQC, MCA, and best-practice guidance.</li><li>Develop effective relationships with commissioners and stakeholders.</li></ul><p><strong>Essential criteria</strong></p><ul><li>Substantial UK leadership experience in adult social care.</li><li>Strong understanding of CQC regulations and inspection readiness.</li><li>Excellent governance, documentation, and people-management skills.</li><li>Level 5 qualification in Leadership for Health and Social Care (or equivalent/desirable).</li></ul><p><strong>Compliance</strong></p><p>Offer is subject to enhanced DBS, employment references, and satisfactory proof of professional eligibility to work in the UK.</p>',
                'closing_date' => now()->addMonths(3)->toDateString(),
            ],
        ];

        foreach ($roles as $role) {
            JobListing::query()->updateOrCreate(
                ['slug' => $role['slug']],
                [
                    'title' => $role['title'],
                    'department' => $role['department'],
                    'location' => $role['location'],
                    'employment_type' => $role['employment_type'],
                    'salary_text' => $role['salary_text'],
                    'description' => $role['description'],
                    'closing_date' => $role['closing_date'],
                    'status' => 'open',
                    'is_published' => true,
                ]
            );
        }
    }

    protected function seedDownloads(): void
    {
        $path = 'seed/hillcrest-information.txt';
        $body = "Hillcrest Living — seeded download\nReplace this placeholder with a branded PDF.";
        Storage::disk('public')->makeDirectory(dirname($path));
        Storage::disk('public')->put($path, $body);

        $media = Media::query()->firstOrCreate(
            ['disk' => 'public', 'path' => $path],
            [
                'filename' => 'Hillcrest-information.txt',
                'mime_type' => 'text/plain',
                'size_bytes' => strlen($body),
                'alt_text' => null,
                'caption' => null,
            ]
        );

        Download::query()->updateOrCreate(
            ['slug' => 'information-sheet'],
            [
                'title' => 'Information sheet',
                'category' => 'Getting started',
                'description' => 'A starter document for enquiries (replace via Filament before production).',
                'media_id' => $media->id,
                'is_published' => true,
                'published_at' => now(),
                'sort_order' => 0,
            ]
        );
    }

    protected function seedHomeGalleryMedia(): void
    {
        $items = [
            ['source' => 'assets/images/hillcrest-gallery-photo-1.png', 'caption' => 'Comfortable spaces', 'alt' => 'Comfortable supported living accommodation at Hillcrest', 'sort_order' => 0],
            ['source' => 'assets/images/hillcrest-gallery-photo-2.png', 'caption' => 'Daily living support', 'alt' => 'Supported living service environment for older adults', 'sort_order' => 10],
            ['source' => 'assets/images/hillcrest-gallery-photo-3.png', 'caption' => 'Calm environments', 'alt' => 'Calm Hillcrest living space close to local community', 'sort_order' => 20],
            ['source' => 'assets/images/hillcrest-community-photo.png', 'caption' => 'Community connection', 'alt' => 'Older adults supported to stay connected with the community', 'sort_order' => 30],
            ['source' => 'assets/images/hillcrest-about-story.png', 'caption' => 'Person-centred support', 'alt' => 'Hillcrest person-centred support in a homely setting', 'sort_order' => 40],
            ['source' => 'assets/images/hillcrest-referral-photo.png', 'caption' => 'Clear referral pathway', 'alt' => 'Friendly referral conversation for supported living', 'sort_order' => 50],
            ['source' => 'assets/images/faq-support-conversation.png', 'caption' => 'Reassuring guidance', 'alt' => 'Support coordinator answering questions with an older adult', 'sort_order' => 60],
            ['source' => 'assets/images/faq-accommodation-support.png', 'caption' => 'Safe accommodation', 'alt' => 'Safe and comfortable supported living accommodation', 'sort_order' => 70],
        ];

        foreach ($items as $item) {
            $sourcePath = public_path($item['source']);
            if (! file_exists($sourcePath)) {
                continue;
            }

            $filename = basename($sourcePath);
            $storagePath = 'home-gallery/'.$filename;
            Storage::disk('public')->put($storagePath, file_get_contents($sourcePath));

            $dimensions = @getimagesize($sourcePath) ?: [null, null];

            Media::query()->updateOrCreate(
                ['disk' => 'public', 'path' => $storagePath],
                [
                    'filename' => $filename,
                    'mime_type' => mime_content_type($sourcePath) ?: 'image/png',
                    'size_bytes' => filesize($sourcePath) ?: null,
                    'alt_text' => $item['alt'],
                    'caption' => $item['caption'],
                    'show_on_home_gallery' => true,
                    'home_gallery_sort_order' => $item['sort_order'],
                    'width' => $dimensions[0],
                    'height' => $dimensions[1],
                ]
            );
        }
    }
}
