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

$baseUrl = 'https://ukdataservices.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-scraping' => '/services/web-scraping',
        'competitive-intelligence' => '/services/competitive-intelligence',
        'price-monitoring' => '/services/price-monitoring',
        'data-cleaning' => '/services/data-cleaning',
        'data-analytics' => '/services/data-analytics',
        '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-scraping' => '/blog/categories/web-scraping',
        '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 = [
    'web-scraping' => [
        'url' => '/services/web-scraping',
        'title' => 'Web Scraping Services',
        'shortTitle' => 'Web Scraping',
        'description' => 'Professional web scraping and data extraction services',
        'icon' => 'icon-web-scraping-v2.svg'
    ],
    'competitive-intelligence' => [
        'url' => '/services/competitive-intelligence',
        'title' => 'Competitive Intelligence',
        'shortTitle' => 'Competitive Intelligence',
        'description' => 'Market analysis and competitor monitoring services',
        'icon' => 'icon-analytics.svg'
    ],
    'price-monitoring' => [
        'url' => '/services/price-monitoring',
        'title' => 'Price Monitoring',
        'shortTitle' => 'Price Monitoring',
        'description' => 'Real-time price tracking and competitor pricing alerts',
        'icon' => 'icon-price-monitoring.svg'
    ],
    'data-cleaning' => [
        'url' => '/services/data-cleaning',
        'title' => 'Data Cleaning & Validation',
        'shortTitle' => 'Data Cleaning',
        'description' => 'Professional data cleaning and quality assurance',
        'icon' => 'icon-data-processing.svg'
    ],
    'data-analytics' => [
        'url' => '/services/data-analytics',
        'title' => 'Data Analytics',
        'shortTitle' => 'Analytics',
        'description' => 'Business intelligence and data analytics solutions',
        'icon' => 'icon-analytics.svg'
    ],
    'api-development' => [
        'url' => '/services/api-development',
        'title' => 'API Development',
        'shortTitle' => 'API Development',
        'description' => 'Custom API development and system integration',
        'icon' => 'icon-automation.svg'
    ],
    'property-data-extraction' => [
        'url' => '/services/property-data-extraction',
        'title' => 'Property Data Extraction',
        'shortTitle' => 'Property Data',
        'description' => 'UK property market data from Rightmove, Zoopla, OnTheMarket',
        'icon' => 'icon-property.svg'
    ],
    'financial-data-services' => [
        'url' => '/services/financial-data-services',
        'title' => 'Financial Data Services',
        'shortTitle' => 'Financial Data',
        'description' => 'FCA-compliant financial and market data extraction',
        'icon' => 'icon-financial.svg'
    ]
];

/**
 * Location metadata for internal linking
 */
$locationData = [
    'london' => [
        'url' => '/locations/london',
        'title' => 'London',
        'region' => 'Greater London',
        'description' => 'Web scraping and data analytics services in London'
    ],
    'manchester' => [
        'url' => '/locations/manchester',
        'title' => 'Manchester',
        'region' => 'Greater Manchester',
        'description' => 'Data analytics and web scraping 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 web scraping 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-scraping' => ['competitive-intelligence', 'price-monitoring', 'data-cleaning'],
    'competitive-intelligence' => ['web-scraping', 'price-monitoring', 'data-analytics'],
    'price-monitoring' => ['web-scraping', 'competitive-intelligence', 'data-analytics'],
    'data-cleaning' => ['web-scraping', 'data-analytics', 'api-development'],
    'data-analytics' => ['competitive-intelligence', 'data-cleaning', 'api-development'],
    'api-development' => ['web-scraping', 'data-cleaning', 'data-analytics'],
    'property-data-extraction' => ['web-scraping', 'data-cleaning', 'competitive-intelligence'],
    'financial-data-services' => ['web-scraping', '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;
}
