<?php

namespace Database\Seeders;

use App\Models\Media;
use App\Models\Service;
use Illuminate\Database\Seeder;

class ServiceSeeder extends Seeder
{
    public function run(): void
    {
        $services = [
            [
                'title' => 'Google Analytics 4 (GA4) Setup',
                'slug' => 'google-analytics-4-ga4-setup',
                'category' => 'Analytics',
                'tags' => ['analytics', 'ga4', 'reporting'],
                'sort_order' => 0,
                'short_description' => 'Event tracking, conversions, reporting.',
                'long_description' => '<p>Full GA4 implementation for websites and landing pages, including event planning, conversion setup, and reporting structures designed around business goals.</p><p>We make sure your analytics account is organized, your event names are meaningful, and your reports are easier to trust.</p>',
                'hero_title' => 'Accurate GA4 Setup That Shows Real Business Results',
                'benefits' => "Event tracking\nConversion setup\nReporting clarity\nReliable data",
                'image' => 'uploads/placeholders/ga4.jpg',
                'image_media_id' => $this->preferredMediaId([
                    'uploads/media/2jfV7sDvnzxNqDruKT45yev8aeQvMHLXHQoowUtM.webp',
                ]),
                'icon' => 'uploads/placeholders/ga4-icon.png',
                'icon_media_id' => $this->preferredMediaId([
                    'uploads/media/v79FaD7gAYHhwhCVU9jXaW6Wyo19v4wpO9OFcmuQ.png',
                ]),
                'seo_title' => 'GA4 Setup Services',
                'seo_description' => 'Get accurate GA4 tracking and reporting for your website.',
            ],
            [
                'title' => 'Google Tag Manager (GTM)',
                'slug' => 'google-tag-manager-gtm',
                'category' => 'Tracking',
                'tags' => ['tag-management', 'tracking', 'gtm'],
                'sort_order' => 1,
                'short_description' => 'Custom tags, triggers, server-side tracking.',
                'long_description' => '<p>GTM setup for scalable tracking, tags, triggers, variables, and cleaner deployment workflows.</p><p>This includes data layer planning, event mapping, and an implementation structure that can support server-side expansion later.</p>',
                'hero_title' => 'Flexible Tag Management Without Editing Code Again and Again',
                'benefits' => "Custom tags\nTrigger logic\nData layer planning\nScalable implementation",
                'image' => 'uploads/placeholders/gtm.jpg',
                'image_media_id' => $this->preferredMediaId([
                    'uploads/media/6CjrhLevKyKTEg5X52DUr8LRDdQJESmjFCnueG4W.png',
                ]),
                'icon' => 'uploads/placeholders/gtm-icon.png',
                'icon_media_id' => $this->preferredMediaId([
                    'uploads/media/kiMpmVYtvcfuAtyLh02wRHiwsu2vLmTiV6kQpQYl.jpg',
                ]),
                'seo_title' => 'GTM Setup Services',
                'seo_description' => 'Scalable Google Tag Manager configuration.',
            ],
            [
                'title' => 'Looker Studio Dashboards',
                'slug' => 'looker-studio-dashboards',
                'category' => 'Reporting',
                'tags' => ['dashboards', 'reporting', 'looker'],
                'sort_order' => 2,
                'short_description' => 'Unified reporting across platforms.',
                'long_description' => '<p>Build executive and marketing dashboards that connect GA4, Google Ads, Meta Ads, and other data sources into one reporting system.</p><p>We focus on clarity, KPI relevance, and dashboards that are simple for teams and clients to understand.</p>',
                'hero_title' => 'Clear Dashboards for Smarter Decisions',
                'benefits' => "Cross-platform reporting\nDashboard automation\nSimplified KPIs",
                'image' => 'uploads/placeholders/looker.jpg',
                'image_media_id' => $this->preferredMediaId([
                    'uploads/media/UVIb8sZBOy3DJRF4pYk5rO19RyPe1albJ1xEojni.png',
                ]),
                'icon' => 'uploads/placeholders/looker-icon.png',
                'icon_media_id' => $this->preferredMediaId([
                    'uploads/media/Y4Bi7JUJUcsDY20kUyTIBtVMZKoSRUljI2g5AXoN.png',
                ]),
                'seo_title' => 'Looker Studio Dashboard Services',
                'seo_description' => 'Unified dashboards for marketing and analytics.',
            ],
            [
                'title' => 'Google Ads Tracking',
                'slug' => 'google-ads-tracking',
                'category' => 'Advertising',
                'tags' => ['advertising', 'ads', 'tracking'],
                'sort_order' => 3,
                'short_description' => 'Conversion tracking, ROI measurement.',
                'long_description' => '<p>Set up conversion tracking for Google Ads campaigns so you can measure leads, sales, and return on ad spend with more confidence.</p><p>We align goals, tags, and reporting so campaign performance is easier to optimize.</p>',
                'hero_title' => 'Track Google Ads Conversions With Confidence',
                'benefits' => "Accurate conversions\nROI visibility\nCampaign measurement",
                'image' => 'uploads/placeholders/google-ads.jpg',
                'image_media_id' => $this->preferredMediaId([
                    'uploads/media/nx7tqNOE2Md4WPPJZzuLLohQRmPxaaniDb6oBPRQ.png',
                ]),
                'icon' => 'uploads/placeholders/google-ads-icon.png',
                'icon_media_id' => $this->preferredMediaId([
                    'uploads/media/s9G0trlaaAP9twGJP9LWkGaxLMNoMgl0uLnchQ7q.png',
                ]),
                'seo_title' => 'Google Ads Tracking Services',
                'seo_description' => 'Accurate conversion measurement for Google Ads.',
            ],
            [
                'title' => 'Meta Ads Tracking (Facebook/Instagram)',
                'slug' => 'meta-ads-tracking-facebook-instagram',
                'category' => 'Advertising',
                'tags' => ['advertising', 'meta', 'pixel'],
                'sort_order' => 4,
                'short_description' => 'Pixel setup, campaign measurement.',
                'long_description' => '<p>Configure Meta Pixel and campaign measurement for Facebook and Instagram ad funnels with stronger event coverage and cleaner attribution.</p><p>We help ensure your key actions are visible to both your team and the platform.</p>',
                'hero_title' => 'Better Meta Pixel Tracking for Better Ad Decisions',
                'benefits' => "Pixel setup\nEvent tracking\nAttribution improvement",
                'image' => 'uploads/placeholders/meta.jpg',
                'image_media_id' => $this->preferredMediaId([
                    'uploads/media/oLV2M4zm3xkLMAJw2XHglJ2xs4Ejcm8II8smXSrb.png',
                ]),
                'icon' => 'uploads/placeholders/meta-icon.png',
                'icon_media_id' => $this->preferredMediaId([
                    'uploads/media/HcPhcJm39jfEcKKBzswosdyEpf1uoIXLTLXBaqW5.png',
                ]),
                'seo_title' => 'Meta Ads Tracking Services',
                'seo_description' => 'High quality Meta Pixel setup and measurement.',
            ],
            [
                'title' => 'TikTok Ads Tracking',
                'slug' => 'tiktok-ads-tracking',
                'category' => 'Advertising',
                'tags' => ['advertising', 'tiktok', 'tracking'],
                'sort_order' => 5,
                'short_description' => 'Event tracking, audience insights.',
                'long_description' => '<p>TikTok tracking setup for events, conversions, and audience behavior insights that support performance-focused campaigns.</p><p>The goal is a cleaner handoff between website activity and platform optimization signals.</p>',
                'hero_title' => 'Smarter TikTok Tracking for Performance Campaigns',
                'benefits' => "Event setup\nConversion data\nAudience insights",
                'image' => 'uploads/placeholders/tiktok.jpg',
                'image_media_id' => $this->preferredMediaId([
                    'uploads/media/j7cTcFcX5wqiMhsfhk4lBuGGEHKs1Qo4M6qMqcmW.png',
                ]),
                'icon' => 'uploads/placeholders/tiktok-icon.png',
                'icon_media_id' => $this->preferredMediaId([
                    'uploads/media/zYN1PnqHn8r1OPnyHYMS29Xvw8xqA9V1BdRG7NqK.png',
                ]),
                'seo_title' => 'TikTok Ads Tracking Services',
                'seo_description' => 'Detailed analytics for TikTok campaigns.',
            ],
            [
                'title' => 'Server-Side Tracking',
                'slug' => 'server-side-tracking',
                'category' => 'Privacy',
                'tags' => ['privacy', 'server-side', 'tracking'],
                'sort_order' => 6,
                'short_description' => 'Advanced tracking for data accuracy and privacy.',
                'long_description' => '<p>Advanced server-side tracking implementation to reduce data loss, improve attribution, and support privacy-focused measurement strategies.</p><p>This is ideal for businesses that need stronger data continuity across browsers and platforms.</p>',
                'hero_title' => 'More Accurate Tracking With Better Data Control',
                'benefits' => "Better accuracy\nPrivacy support\nReduced tracking loss",
                'image' => 'uploads/placeholders/server-side.jpg',
                'image_media_id' => $this->preferredMediaId([
                    'uploads/media/e8bTxQAhm5KtudWpwVuUuQzV7jt6ethzBLHghSuU.png',
                ]),
                'icon' => 'uploads/placeholders/server-side-icon.png',
                'icon_media_id' => $this->preferredMediaId([
                    'uploads/media/iJcm5ue8eXcbASnWFv0OMQgo4xkilmSfM3vT7Gd8.png',
                ]),
                'seo_title' => 'Server Side Tracking Services',
                'seo_description' => 'Enhanced accuracy with server side data collection.',
            ],
        ];

        foreach ($services as $data) {
            Service::updateOrCreate(['slug' => $data['slug']], $data);
        }
    }

    protected function mediaId(string $path): ?int
    {
        return Media::query()->where('file_path', $path)->value('id');
    }

    protected function preferredMediaId(array $paths): ?int
    {
        foreach ($paths as $path) {
            $id = $this->mediaId($path);

            if ($id) {
                return $id;
            }
        }

        return null;
    }
}
