<?php
/**
 * URL Configuration
 * Centralized URL mapping for internal linking consistency
 *
 * Usage:
 * include($_SERVER['DOCUMENT_ROOT'] . '/includes/url-config.php');
 * echo $urlMap['services']['web-Automation'];
 */

$baseUrl = 'https://ukaiautomation.co.uk';

/**
 * Complete URL map for the site
 */
$urlMap = [
    'home' => '/',
    'about' => '/about',
    'quote' => '/quote',
    'faq' => '/faq',
    'blog' => '/blog',
    'contact' => '/#contact',
    'project-types' => '/project-types',
    'case-studies' => '/case-studies',

    // Services
    'services' => [
        'index' => '/#services',
        'web-Automation' => '/services/web-Automation',
        'competitive-intelligence' => '/services/competitive-intelligence',
        'price-monitoring' => '/services/price-monitoring',
        'data-cleaning' => '/services/data-cleaning',
        'data-analytics' => '/services/data-analysis-services',
        'api-development' => '/services/api-development',
        'property-data-extraction' => '/services/property-data-extraction',
        'financial-data-services' => '/services/financial-data-services'
    ],

    // Locations
    'locations' => [
        'index' => '/locations',
        'london' => '/locations/london',
        'manchester' => '/locations/manchester',
        'birmingham' => '/locations/birmingham',
        'edinburgh' => '/locations/edinburgh',
        'cardiff' => '/locations/cardiff'
    ],

    // Blog categories
    'blog-categories' => [
        'web-Automation' => '/blog/categories/web-Automation',
        'data-analytics' => '/blog/categories/data-analytics',
        'business-intelligence' => '/blog/categories/business-intelligence',
        'compliance' => '/blog/categories/compliance',
        'industry-insights' => '/blog/categories/industry-insights',
        'technology' => '/blog/categories/technology',
        'case-studies' => '/blog/categories/case-studies'
    ],

    // Legal pages
    'legal' => [
        'privacy-policy' => '/privacy-policy',
        'terms-of-service' => '/terms-of-service',
        'cookie-policy' => '/cookie-policy',
        'gdpr-compliance' => '/gdpr-compliance'
    ]
];

/**
 * Service metadata for internal linking and SEO
 */
$serviceData = [
    'document-extraction' => [
        'url' => '/#services',
        'title' => 'Document Extraction',
        'shortTitle' => 'Document Extraction',
        'description' => 'Automated extraction from PDFs, Word docs, contracts and reports',
        'icon' => 'icon-data-processing.svg'
    ],
    'research-automation' => [
        'url' => '/#services',
        'title' => 'Research Automation',
        'shortTitle' => 'Research Automation',
        'description' => 'Automated market research, due diligence and competitor monitoring',
        'icon' => 'icon-analytics.svg'
    ],
    'data-pipelines' => [
        'url' => '/#services',
        'title' => 'Data Pipeline Build-Outs',
        'shortTitle' => 'Data Pipelines',
        'description' => 'End-to-end data pipelines from messy sources to clean structured outputs',
        'icon' => 'icon-automation.svg'
    ],
    'custom-ai-agents' => [
        'url' => '/#services',
        'title' => 'Custom AI Agents',
        'shortTitle' => 'AI Agents',
        'description' => 'Bespoke AI agents that handle repetitive workflows autonomously',
        'icon' => 'icon-web-scraping-v2.svg'
    ],
];

/**
 * Location metadata for internal linking
 */
$locationData = [
    'london' => [
        'url' => '/locations/london',
        'title' => 'London',
        'region' => 'Greater London',
        'description' => 'AI Automation and data analytics services in London'
    ],
    'manchester' => [
        'url' => '/locations/manchester',
        'title' => 'Manchester',
        'region' => 'Greater Manchester',
        'description' => 'Data analytics and AI Automation Services in Manchester'
    ],
    'birmingham' => [
        'url' => '/locations/birmingham',
        'title' => 'Birmingham',
        'region' => 'West Midlands',
        'description' => 'Data services and business intelligence in Birmingham'
    ],
    'edinburgh' => [
        'url' => '/locations/edinburgh',
        'title' => 'Edinburgh',
        'region' => 'Scotland',
        'description' => 'Data analytics and AI Automation Services in Edinburgh'
    ],
    'cardiff' => [
        'url' => '/locations/cardiff',
        'title' => 'Cardiff',
        'region' => 'Wales',
        'description' => 'Data services and business intelligence in Cardiff'
    ]
];

/**
 * Related services mapping for cross-linking
 */
$relatedServices = [
    'web-Automation' => ['competitive-intelligence', 'price-monitoring', 'data-cleaning'],
    'competitive-intelligence' => ['web-Automation', 'price-monitoring', 'data-analytics'],
    'price-monitoring' => ['web-Automation', 'competitive-intelligence', 'data-analytics'],
    'data-cleaning' => ['web-Automation', 'data-analytics', 'api-development'],
    'data-analytics' => ['competitive-intelligence', 'data-cleaning', 'api-development'],
    'api-development' => ['web-Automation', 'data-cleaning', 'data-analytics'],
    'property-data-extraction' => ['web-Automation', 'data-cleaning', 'competitive-intelligence'],
    'financial-data-services' => ['web-Automation', 'data-analytics', 'api-development']
];

/**
 * Get full URL with base URL
 *
 * @param string $path Relative path
 * @return string Full URL
 */
function getFullUrl($path) {
    global $baseUrl;
    return $baseUrl . $path;
}

/**
 * Get service URL by key
 *
 * @param string $serviceKey Service identifier
 * @return string Service URL
 */
function getServiceUrl($serviceKey) {
    global $urlMap;
    return $urlMap['services'][$serviceKey] ?? '/#services';
}

/**
 * Get location URL by key
 *
 * @param string $locationKey Location identifier
 * @return string Location URL
 */
function getLocationUrl($locationKey) {
    global $urlMap;
    return $urlMap['locations'][$locationKey] ?? '/';
}

/**
 * Get related services for a given service
 *
 * @param string $serviceKey Current service key
 * @return array Array of related service data
 */
function getRelatedServices($serviceKey) {
    global $relatedServices, $serviceData;

    $related = $relatedServices[$serviceKey] ?? [];
    $result = [];

    foreach ($related as $relatedKey) {
        if (isset($serviceData[$relatedKey])) {
            $result[] = $serviceData[$relatedKey];
        }
    }

    return $result;
}
