"""Sector-based curated reference library with verified, working URLs."""

SECTOR_REFERENCES = {
    "technology": {
        "keywords": [
            "tech", "software", "app", "platform", "saas", "digital",
            "ai", "artificial intelligence", "blockchain", "cloud",
            "programming", "website", "portal", "automation", "machine learning",
            "تقنية", "برمجيات", "تطبيق", "منصة", "رقمي", "ذكاء اصطناعي",
            "برمجة", "موقع", "سحابي", "برمجي", "تكنولوجيا", "نظام",
        ],
        "references": [
            {
                "source": "Industry Report",
                "title": "Saudi Arabia ICT Market Overview",
                "url": "https://www.statista.com",
                "description": "Statista - Digital services market size and forecasts for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Digital Transformation",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/digital-transformation",
                "description": "Saudi Vision 2030 - National digital transformation strategy and targets",
            },
            {
                "source": "Government",
                "title": "Saudi Arabia - Communications, Space & Technology Commission",
                "url": "https://www.cst.gov.sa/en/Indicators/Pages/default.aspx",
                "description": "CST - ICT sector indicators and market data for Saudi Arabia",
            },
            {
                "source": "Research",
                "title": "Mckinsey - Digital Middle East Report",
                "url": "https://www.mckinsey.com/featured-insights/middle-east-and-africa/digital-middle-east",
                "description": "Mckinsey & Company - Digital transformation trends in the Middle East",
            },
            {
                "source": "Government",
                "title": "Saudi Authority for Data and Artificial Intelligence (SDAIA)",
                "url": "https://sdaia.gov.sa/en/SDAIA/Pages/About.aspx",
                "description": "SDAIA - National AI and data strategy for Saudi Arabia",
            },
        ],
    },
    "food_beverage": {
        "keywords": [
            "restaurant", "cafe", "coffee", "food", "beverage", "drink",
            "bakery", "catering", "kitchen", "meal", "fast food", "juice",
            "ice cream", "chocolate", "snack", "confectionery", "grocery",
            "مطعم", "كافي", "قهوة", "طعام", "مشروب", "شراب", "مخبز",
            "تموين", "مطبخ", "وجبة", "وجبات", "عصير", "ايس كريم", "شوكولاتة",
            "مقبلات", "حلويات", "بقالة", "سوبرماركت", "مطاعم",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Saudi Food and Drug Authority - Market Data",
                "url": "https://sfda.gov.sa/en/awareness",
                "description": "SFDA - Food sector regulations and market information for Saudi Arabia",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Food Service Market",
                "url": "https://www.statista.com",
                "description": "Statista - Food service market size, trends, and forecasts for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Ministry of Environment, Water and Agriculture - Saudi Arabia",
                "url": "https://mewa.gov.sa/en/Pages/default.aspx",
                "description": "MEWA - Agricultural and food sector policies and statistics",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Coffee Market Overview",
                "url": "https://www.statista.com",
                "description": "Statista - Coffee market size, consumption trends, and forecasts for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Arabian General Investment Authority - Food Sector",
                "url": "https://investsaudi.sa/en/sectors-opportunities/food-processing",
                "description": "Invest Saudi - Food processing sector investment opportunities in Saudi Arabia",
            },
        ],
    },
    "retail_ecommerce": {
        "keywords": [
            "retail", "ecommerce", "e-commerce", "online store", "shop",
            "marketplace", "consumer goods", "wholesale", "franchise",
            "supermarket", "hypermarket", "convenience store", "boutique",
            "متجر", "تجزئة", "تجارة", "متجر الكتروني", "سوق", "متجر إلكتروني",
            "متجر الكتروني", "بيع", "مشتريات", "تسوق", "متاجر",
        ],
        "references": [
            {
                "source": "Industry Report",
                "title": "Saudi Arabia E-commerce Market",
                "url": "https://www.statista.com/outlook/emo/ecommerce/saudi-arabia",
                "description": "Statista - E-commerce market size, user data, and revenue forecasts for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Ministry of Commerce - Saudi Arabia",
                "url": "https://mc.gov.sa/en/Pages/default.aspx",
                "description": "Ministry of Commerce - Retail sector regulations and business data",
            },
            {
                "source": "Government",
                "title": "Saudi E-commerce Council",
                "url": "https://ecommerce.gov.sa/en",
                "description": "Saudi E-commerce Council - National e-commerce strategy and initiatives",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Retail Market Overview",
                "url": "https://www.statista.com",
                "description": "Statista - Retail market data including offline and online channels",
            },
            {
                "source": "Government",
                "title": "Invest Saudi - Retail Sector Opportunities",
                "url": "https://investsaudi.sa/en/sectors-opportunities/retail",
                "description": "Invest Saudi - Retail sector investment landscape and opportunities",
            },
        ],
    },
    "manufacturing": {
        "keywords": [
            "manufacturing", "factory", "production", "industrial",
            "assembly", "processing", "machinery", "equipment",
            "plant", "workshop", "fabrication", "foundry",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Saudi Industrial Development Fund (SIDF)",
                "url": "https://www.sidf.gov.sa/en/Pages/default.aspx",
                "description": "SIDF - Industrial project financing and support in Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Ministry of Industry and Mineral Resources - Saudi Arabia",
                "url": "https://mim.gov.sa/en/Pages/default.aspx",
                "description": "Ministry of Industry - Industrial sector regulations and licensing in Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Industrial Development",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/industrial-development",
                "description": "Saudi Vision 2030 - National industrial development and localization strategy",
            },
            {
                "source": "Government",
                "title": "Invest Saudi - Manufacturing Sector",
                "url": "https://investsaudi.sa/en/sectors-opportunities/manufacturing",
                "description": "Invest Saudi - Manufacturing investment opportunities and incentives",
            },
            {
                "source": "International",
                "title": "World Bank - Manufacturing Value Added Data",
                "url": "https://data.worldbank.org/indicator/NV.IND.MANF.ZS",
                "description": "World Bank - Manufacturing value added as percentage of GDP for global comparison",
            },
        ],
    },
    "healthcare": {
        "keywords": [
            "healthcare", "hospital", "clinic", "medical", "pharma",
            "pharmaceutical", "health", "wellness", "doctor", "medicine",
            "diagnostic", "laboratory", "pharmacy", "therapy", "nursing",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Saudi Ministry of Health - Statistics & Reports",
                "url": "https://www.moh.gov.sa/en/Ministry/Statistics/Pages/default.aspx",
                "description": "MOH - Healthcare statistics, indicators, and annual reports for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Health Council - National Health Strategy",
                "url": "https://shc.gov.sa/en/Pages/default.aspx",
                "description": "Saudi Health Council - Healthcare sector strategy and transformation",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Healthcare Market",
                "url": "https://www.statista.com",
                "description": "Statista - Healthcare market size, spending, and forecasts for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Health Sector Transformation",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/health-sector-transformation",
                "description": "Saudi Vision 2030 - Healthcare transformation program objectives and KPIs",
            },
            {
                "source": "International",
                "title": "World Health Organization - Saudi Arabia Data",
                "url": "https://data.who.int/countries/682",
                "description": "WHO - Health indicators and statistics for Saudi Arabia",
            },
        ],
    },
    "education": {
        "keywords": [
            "education", "school", "university", "college", "training",
            "academy", "institute", "learning", "course", "tutorial",
            "online learning", "e-learning", "edtech", "coaching",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Saudi Ministry of Education - Statistics",
                "url": "https://moe.gov.sa/en/Pages/default.aspx",
                "description": "Ministry of Education - Education sector data and statistics for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Education & Training",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/human-capital-development",
                "description": "Saudi Vision 2030 - Human capital development, education targets, and programs",
            },
            {
                "source": "International",
                "title": "World Bank - Education Statistics Saudi Arabia",
                "url": "https://data.worldbank.org/indicator/SE.PRM.ENRR?locations=SA",
                "description": "World Bank - Education enrollment rates and literacy data for Saudi Arabia",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia E-learning Market",
                "url": "https://www.statista.com",
                "description": "Statista - E-learning market size, user penetration, and revenue forecasts",
            },
            {
                "source": "Industry Report",
                "title": "Mckinsey - Future of Education in the Middle East",
                "url": "https://www.mckinsey.com/industries/education/our-insights",
                "description": "Mckinsey - Education industry insights and trends for the Middle East region",
            },
        ],
    },
    "agriculture": {
        "keywords": [
            "agriculture", "farm", "farming", "crop", "livestock",
            "agritech", "agribusiness", "organic", "greenhouse",
            "poultry", "dairy", "fishery", "aquaculture", "irrigation",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Ministry of Environment, Water and Agriculture - Saudi Arabia",
                "url": "https://mewa.gov.sa/en/Pages/default.aspx",
                "description": "MEWA - Agricultural policies, programs, and statistics for Saudi Arabia",
            },
            {
                "source": "International",
                "title": "FAO - Food and Agriculture Data Saudi Arabia",
                "url": "https://www.fao.org/faostat/en/#country/194",
                "description": "FAO - Agricultural production, trade, and resource data for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Agricultural and Livestock Investment Company (SALIC)",
                "url": "https://salic.com/en/Pages/default.aspx",
                "description": "SALIC - Agricultural investment and food security initiatives for Saudi Arabia",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Agriculture Market Overview",
                "url": "https://www.statista.com/topics/8967/agriculture-in-saudi-arabia",
                "description": "Statista - Agriculture sector statistics, production volumes, and market data",
            },
            {
                "source": "Government",
                "title": "Vision 2030 - Environmental Sustainability & Agriculture",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/environmental-stewardship",
                "description": "Saudi Vision 2030 - Agricultural sustainability and food security goals",
            },
        ],
    },
    "real_estate_construction": {
        "keywords": [
            "real estate", "construction", "property", "housing",
            "apartment", "villa", "building", "contractor", "development",
            "infrastructure", "renovation", "interior design", "architect",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Ministry of Municipal and Rural Affairs - Saudi Arabia",
                "url": "https://momrah.gov.sa/en/Pages/default.aspx",
                "description": "Ministry of Municipal and Rural Affairs - Urban development and housing data",
            },
            {
                "source": "Government",
                "title": "Saudi Real Estate Authority",
                "url": "https://rega.gov.sa/en/Pages/default.aspx",
                "description": "Real Estate Authority - Real estate sector regulation and market data for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Housing Program",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/housing",
                "description": "Vision 2030 - Housing program targets and achievements in Saudi Arabia",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Real Estate Market",
                "url": "https://www.statista.com",
                "description": "Statista - Real estate market size, property prices, and forecasts",
            },
            {
                "source": "Government",
                "title": "Saudi Real Estate Development Fund",
                "url": "https://redf.gov.sa/en/Pages/default.aspx",
                "description": "REDF - Real estate financing programs and housing loan data for Saudi Arabia",
            },
        ],
    },
    "transportation_logistics": {
        "keywords": [
            "transportation", "logistics", "delivery", "shipping",
            "courier", "fleet", "trucking", "warehouse", "supply chain",
            "freight", "cargo", "ridesharing", "taxi", "aviation",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Saudi Transport and Logistics Authority",
                "url": "https://tga.gov.sa/en/Pages/default.aspx",
                "description": "TGA - Transportation sector regulation, statistics, and market data for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - National Industrial Development and Logistics Program",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/national-industrial-development-and-logistics-program",
                "description": "Vision 2030 - Logistics sector transformation program targets and initiatives",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Logistics Market",
                "url": "https://www.statista.com",
                "description": "Statista - Logistics market size, segments, and growth forecasts",
            },
            {
                "source": "Government",
                "title": "Saudi Ports Authority (Mawani)",
                "url": "https://mawani.gov.sa/en/Pages/default.aspx",
                "description": "Mawani - Port traffic statistics, trade volumes, and maritime sector data",
            },
            {
                "source": "International",
                "title": "World Bank - Logistics Performance Index Saudi Arabia",
                "url": "https://lpi.worldbank.org/international/global/2018",
                "description": "World Bank - Logistics performance ranking and infrastructure indicators",
            },
        ],
    },
    "energy_renewable": {
        "keywords": [
            "energy", "solar", "renewable", "wind", "power", "electricity",
            "oil", "gas", "petroleum", "clean energy", "green energy",
            "sustainability", "carbon", "environment", "solar panel",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Saudi Ministry of Energy",
                "url": "https://www.moenergy.gov.sa/en/Pages/default.aspx",
                "description": "Ministry of Energy - Energy sector policies, production data, and initiatives",
            },
            {
                "source": "Government",
                "title": "King Abdullah City for Atomic and Renewable Energy (KACARE)",
                "url": "https://www.kacare.gov.sa/en/Pages/default.aspx",
                "description": "KACARE - Renewable energy data, research, and national energy strategy",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Renewable Energy Targets",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/renewable-energy",
                "description": "Vision 2030 - Renewable energy capacity targets and achievements",
            },
            {
                "source": "International",
                "title": "IRENA - Saudi Arabia Renewable Energy Profile",
                "url": "https://www.irena.org/IRENADocuments/Statistical_Profiles/Middle%20East/Saudi%20Arabia_Middle%20East_RE_SP.pdf",
                "description": "IRENA - Renewable energy capacity, investment, and policy data for Saudi Arabia",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Solar Energy Market",
                "url": "https://www.statista.com",
                "description": "Statista - Solar energy market size, installations, and growth forecasts",
            },
        ],
    },
    "tourism_hospitality": {
        "keywords": [
            "tourism", "hotel", "resort", "travel", "hospitality",
            "tourist", "visitor", "leisure", "entertainment", "recreation",
            "cultural", "heritage", "museum", "event", "conference",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Saudi Ministry of Tourism",
                "url": "https://www.mt.gov.sa/en/Pages/default.aspx",
                "description": "Ministry of Tourism - Tourism sector data, strategies, and investment opportunities",
            },
            {
                "source": "Government",
                "title": "Saudi Tourism Authority - Visit Saudi",
                "url": "https://www.visitsaudi.com/en",
                "description": "Visit Saudi - Tourism statistics, attractions, and visitor information",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Tourism Development",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/tourism",
                "description": "Vision 2030 - Tourism sector targets, including 100M annual visits by 2030",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Tourism Market",
                "url": "https://www.statista.com",
                "description": "Statista - Travel and tourism market size, visitor numbers, and spending data",
            },
            {
                "source": "Government",
                "title": "Saudi Red Sea Authority",
                "url": "https://www.redsea.gov.sa/en/Pages/default.aspx",
                "description": "Red Sea Authority - Coastal tourism development and investment in Saudi Arabia",
            },
        ],
    },
    "fashion_beauty": {
        "keywords": [
            "fashion", "clothing", "apparel", "beauty", "cosmetic",
            "perfume", "skincare", "hair", "makeup", "accessories",
            "jewelry", "watch", "fragrance", "attar", "oud",
        ],
        "references": [
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Beauty & Personal Care Market",
                "url": "https://www.statista.com/outlook/cmo/beauty-personal-care/saudi-arabia",
                "description": "Statista - Beauty and personal care market size, segments, and forecasts",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Fashion Market Overview",
                "url": "https://www.statista.com/outlook/cmo/apparel/saudi-arabia",
                "description": "Statista - Apparel and fashion market size, consumer trends, and revenue data",
            },
            {
                "source": "Government",
                "title": "Saudi Fashion Commission",
                "url": "https://fashion.moc.gov.sa/en/Pages/default.aspx",
                "description": "Saudi Fashion Commission - Fashion sector development and industry data",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Perfume Market",
                "url": "https://www.statista.com",
                "description": "Statista - Fragrance and perfume market size, consumer preferences, and growth",
            },
            {
                "source": "Government",
                "title": "Invest Saudi - Fashion & Beauty Sector",
                "url": "https://investsaudi.sa/en/sectors-opportunities/fashion-and-beauty",
                "description": "Invest Saudi - Fashion and beauty sector investment opportunities and ecosystem",
            },
        ],
    },
    "fintech_financial": {
        "keywords": [
            "fintech", "financial", "banking", "bank", "payment",
            "insurance", "investment", "finance", "lending", "loan",
            "crowdfunding", "remittance", "currency", "capital",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Saudi Central Bank (SAMA) - Financial Reports",
                "url": "https://www.sama.gov.sa/en-US/EconomicReports/Pages/default.aspx",
                "description": "SAMA - Financial sector statistics, monetary reports, and economic data",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Financial Sector Development Program",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/financial-sector-development-program",
                "description": "Vision 2030 - Financial sector transformation, Fintech strategy, and targets",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Fintech Market",
                "url": "https://www.statista.com/outlook/dmo/fintech/saudi-arabia",
                "description": "Statista - Fintech market size, digital payments, and adoption rates",
            },
            {
                "source": "Government",
                "title": "Saudi Capital Market Authority (CMA)",
                "url": "https://cma.org.sa/en/Pages/default.aspx",
                "description": "CMA - Capital market regulations, IPO data, and investment statistics",
            },
            {
                "source": "International",
                "title": "IMF - Saudi Arabia Financial System Stability Assessment",
                "url": "https://www.imf.org/en/Countries/SAU",
                "description": "IMF - Saudi Arabia economic outlook, financial sector assessment, and data",
            },
        ],
    },
    "cleaning_maintenance": {
        "keywords": [
            "cleaning", "maintenance", "laundry", "dry cleaning",
            "janitorial", "sanitation", "pest control", "facility management",
            "disinfection", "washing", "housekeeping",
        ],
        "references": [
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Cleaning Services Market",
                "url": "https://www.statista.com",
                "description": "Statista - Cleaning services market size, segments, and growth forecasts",
            },
            {
                "source": "Government",
                "title": "Saudi Ministry of Commerce - Business Registration",
                "url": "https://mc.gov.sa/en/Pages/default.aspx",
                "description": "Ministry of Commerce - Commercial registration requirements for service businesses",
            },
            {
                "source": "Government",
                "title": "Saudi Small and Medium Enterprises General Authority (Monshaat)",
                "url": "https://monshaat.gov.sa/en/Pages/default.aspx",
                "description": "Monshaat - SME sector data, support programs, and entrepreneurial ecosystem",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Facility Management Market",
                "url": "https://www.statista.com",
                "description": "Statista - Facility management market including cleaning and maintenance services",
            },
            {
                "source": "International",
                "title": "World Bank - Saudi Arabia Business Environment",
                "url": "https://www.worldbank.org/en/country/saudiarabia",
                "description": "World Bank - Business environment, licensing, and regulatory framework data",
            },
        ],
    },
    "automotive": {
        "keywords": [
            "automotive", "car", "vehicle", "auto", "garage",
            "maintenance center", "car wash", "rental car",
            "workshop", "tire", "spare parts", "electric vehicle",
        ],
        "references": [
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Automotive Market",
                "url": "https://www.statista.com",
                "description": "Statista - Automotive market size, vehicle sales, and industry forecasts",
            },
            {
                "source": "Government",
                "title": "Saudi Standards, Metrology and Quality Organization (SASO)",
                "url": "https://saso.gov.sa/en/Pages/default.aspx",
                "description": "SASO - Vehicle standards, regulations, and quality requirements in Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Ministry of Transport and Logistics",
                "url": "https://www.mot.gov.sa/en/Pages/default.aspx",
                "description": "Ministry of Transport - Transportation sector data, licensing, and regulations",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Electric Vehicle Market",
                "url": "https://www.statista.com/outlook/mmo/electric-vehicles/saudi-arabia",
                "description": "Statista - EV market size, adoption rates, and infrastructure development",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Automotive Industry Localization",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/national-industrial-development-and-logistics-program",
                "description": "Vision 2030 - Automotive manufacturing localization and industry development",
            },
        ],
    },
    "media_entertainment": {
        "keywords": [
            "media", "entertainment", "film", "video", "music",
            "gaming", "content", "production", "broadcast", "streaming",
            "social media", "marketing", "advertising", "publishing",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Saudi General Entertainment Authority (GEA)",
                "url": "https://www.gea.gov.sa/en/Pages/default.aspx",
                "description": "GEA - Entertainment sector strategy, events, and market development in Saudi Arabia",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Media & Entertainment Market",
                "url": "https://www.statista.com/outlook/amo/media/saudi-arabia",
                "description": "Statista - Media and entertainment market size, segments, and revenue data",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Quality of Life Program",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/quality-of-life-program",
                "description": "Vision 2030 - Entertainment, culture, and quality of life initiatives and targets",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Gaming Market Overview",
                "url": "https://www.statista.com/outlook/dmo/digital-media/video-games/saudi-arabia",
                "description": "Statista - Gaming market size, players, and revenue in Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Ministry of Media",
                "url": "https://www.media.gov.sa/en/Pages/default.aspx",
                "description": "Ministry of Media - Media sector regulations, licensing, and industry statistics",
            },
        ],
    },
    "sports_fitness": {
        "keywords": [
            "sports", "fitness", "gym", "training", "athletic",
            "football", "soccer", "basketball", "swimming",
            "yoga", "wellness", "nutrition", "supplement",
        ],
        "references": [
            {
                "source": "Government",
                "title": "Saudi Ministry of Sports",
                "url": "https://www.mos.gov.sa/en/Pages/default.aspx",
                "description": "Ministry of Sports - Sports sector development, programs, and data",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Fitness Market",
                "url": "https://www.statista.com",
                "description": "Statista - Fitness market size, gym memberships, and health club data",
            },
            {
                "source": "Government",
                "title": "Saudi Sports for All Federation",
                "url": "https://sportsforall.com.sa/en",
                "description": "Sports for All - Community sports programs and physical activity statistics",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Sports Development",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/quality-of-life-program",
                "description": "Vision 2030 - Sports participation targets and athletic development goals",
            },
            {
                "source": "International",
                "title": "World Health Organization - Physical Activity Data Saudi Arabia",
                "url": "https://www.who.int/data/gho/data/indicators/indicator-details/GHO/prevalence-of-insufficient-physical-activity",
                "description": "WHO - Physical activity prevalence and health indicators for Saudi Arabia",
            },
        ],
    },
    "robotics_automation": {
        "keywords": [
            "robot", "robotic", "automation", "drone", "machine",
            "smart device", "iot", "sensor", "smart home",
            "vacuum cleaner", "autonomous", "industrial robot",
        ],
        "references": [
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Robotics Market",
                "url": "https://www.statista.com",
                "description": "Statista - Robotics market size, segments, and growth forecasts for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi Authority for Industrial Cities and Technology Zones (MODON)",
                "url": "https://www.modon.gov.sa/en/Pages/default.aspx",
                "description": "MODON - Industrial cities infrastructure and technology zone development",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Technology & Innovation",
                "url": "https://www.vision2030.gov.sa/en/vision-2030/vrp/research-and-development",
                "description": "Vision 2030 - R&D investment targets and technology innovation strategy",
            },
            {
                "source": "Industry Report",
                "title": "Global Robotics Market Overview",
                "url": "https://www.statista.com/topics/2710/robotics",
                "description": "Statista - Global robotics market data including service robots and industrial robots",
            },
            {
                "source": "International",
                "title": "World Bank - High-Technology Exports Data",
                "url": "https://data.worldbank.org/indicator/TX.VAL.TECH.MF.ZS",
                "description": "World Bank - Technology exports data for global market comparison",
            },
        ],
    },
    "ecommerce_marketplace": {
        "keywords": [
            "marketplace", "ecommerce", "e-commerce", "online platform",
            "buy and sell", "classified", "auction", "b2b", "b2c",
            "dropshipping", "subscription", "box",
        ],
        "references": [
            {
                "source": "Industry Report",
                "title": "Saudi Arabia E-commerce Market Overview",
                "url": "https://www.statista.com/outlook/emo/ecommerce/saudi-arabia",
                "description": "Statista - E-commerce revenue, user penetration, and platform data for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Saudi E-commerce Council - National Strategy",
                "url": "https://ecommerce.gov.sa/en/Initiatives/Pages/default.aspx",
                "description": "Saudi E-commerce Council - E-commerce initiatives, regulations, and market data",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Online Marketplace Trends",
                "url": "https://www.statista.com/outlook/emo/ecommerce/marketplace/saudi-arabia",
                "description": "Statista - Online marketplace transaction value and platform trends",
            },
            {
                "source": "International",
                "title": "World Bank - Digital Adoption Index Saudi Arabia",
                "url": "https://www.worldbank.org/en/publication/wdr2016/Digital-Adoption-Index",
                "description": "World Bank - Digital adoption indicators and internet economy data",
            },
            {
                "source": "Government",
                "title": "Saudi CST - Internet and E-commerce Indicators",
                "url": "https://www.cst.gov.sa/en/Indicators/Pages/default.aspx",
                "description": "CST - Internet penetration, e-commerce adoption, and digital indicators",
            },
        ],
    },
    "logistics_delivery": {
        "keywords": [
            "delivery", "logistics", "courier", "shipping", "last mile",
            "express", "parcel", "dispatch", "fleet", "dispatch",
            "truck", "van", "rider", "driver",
        ],
        "references": [
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Last-Mile Delivery Market",
                "url": "https://www.statista.com",
                "description": "Statista - Last-mile delivery market size, segments, and growth forecasts",
            },
            {
                "source": "Government",
                "title": "Saudi Transport General Authority - Courier Sector",
                "url": "https://tga.gov.sa/en/Pages/default.aspx",
                "description": "TGA - Courier and delivery sector regulations, licensing, and market data",
            },
            {
                "source": "Industry Report",
                "title": "Saudi Arabia Express Delivery Market",
                "url": "https://www.statista.com",
                "description": "Statista - Express delivery market size and competitive landscape",
            },
            {
                "source": "Government",
                "title": "Saudi Postal Corporation (SPL)",
                "url": "https://splonline.com.sa/en/Pages/default.aspx",
                "description": "SPL - Postal and logistics services data, network coverage, and volumes",
            },
            {
                "source": "International",
                "title": "World Bank - Logistics Performance Index",
                "url": "https://lpi.worldbank.org/international/global/2018",
                "description": "World Bank - Logistics performance rankings and infrastructure indicators",
            },
        ],
    },
    "general_sme": {
        "keywords": [],  # fallback for any project that doesn't match other sectors
        "references": [
            {
                "source": "Government",
                "title": "Saudi SME Authority (Monshaat) - SME Report",
                "url": "https://monshaat.gov.sa/en/sme-report/Pages/default.aspx",
                "description": "Monshaat - SME sector data, trends, and entrepreneurial ecosystem in Saudi Arabia",
            },
            {
                "source": "International",
                "title": "World Bank - Saudi Arabia Economic Overview",
                "url": "https://www.worldbank.org/en/country/saudiarabia/overview",
                "description": "World Bank - Saudi Arabia economic data, growth indicators, and development priorities",
            },
            {
                "source": "Government",
                "title": "Saudi Vision 2030 - Economic Dashboard",
                "url": "https://www.vision2030.gov.sa/en/progress",
                "description": "Vision 2030 - Economic progress indicators, targets, and achievement data",
            },
            {
                "source": "International",
                "title": "IMF - Saudi Arabia Economic Outlook",
                "url": "https://www.imf.org/en/Countries/SAU/SAU-dashboard",
                "description": "IMF - Saudi Arabia GDP, inflation, fiscal data, and economic projections",
            },
            {
                "source": "International",
                "title": "OECD - Saudi Arabia Country Profile",
                "url": "https://www.oecd.org/en/countries/saudi-arabia.html",
                "description": "OECD - Economic surveys and country data for Saudi Arabia",
            },
            {
                "source": "Government",
                "title": "Invest Saudi - Business Environment",
                "url": "https://investsaudi.sa/en/why-saudi-arabia",
                "description": "Invest Saudi - Investment incentives, business setup guide, and sector opportunities",
            },
            {
                "source": "Government",
                "title": "Saudi Ministry of Commerce - Business Registration Guide",
                "url": "https://mc.gov.sa/en/Pages/default.aspx",
                "description": "Ministry of Commerce - Company registration, commercial laws, and business services",
            },
            {
                "source": "Industry Report",
                "title": "Global Entrepreneurship Monitor - Saudi Arabia",
                "url": "https://www.gemconsortium.org/economy-profiles/saudi-arabia",
                "description": "GEM - Entrepreneurship indicators, startup activity, and innovation data",
            },
            {
                "source": "International",
                "title": "World Economic Forum - Saudi Arabia Competitiveness",
                "url": "https://www.weforum.org/publications/the-global-competitiveness-report-2020",
                "description": "WEF - Global competitiveness indicators and economic performance data",
            },
        ],
    },
}


ARABIC_KEYWORD_MAP = {
    "technology": ["تقنية", "برمج", "تطبيق", "منصة", "رقم", "ذكاء اصطناعي", "سحابة", "برمجة", "موقع", "تكنولوجيا", "نظام"],
    "food_beverage": ["مطعم", "قهوة", "طعام", "مشروب", "مخبز", "مطبخ", "وجبة", "عصير", "ايس كريم", "شوكولاتة", "حلويات"],
    "retail_ecommerce": ["متجر", "تجزئة", "بيع", "تسوق", "سوق", "متاجر", "تجارة"],
    "manufacturing": ["مصنع", "تصنيع", "صناعة", "إنتاج", "ورشة", "معمل", "معدات", "آلة"],
    "healthcare": ["مستشفى", "عيادة", "طبي", "صحي", "دواء", "صيدلية", "علاج", "صحة"],
    "education": ["مدرسة", "جامعة", "تعليم", "تدريب", "أكاديمية", "معهد", "دورة", "تعلم"],
    "agriculture": ["زراعة", "مزرعة", "محصول", "ثروة", "غذاء", "بيوت محمية", "دواجن", "أسماك"],
    "real_estate_construction": ["عقار", "بناء", "مقاولات", "سكن", "فيلا", "شقة", "تطوير", "هندسة"],
    "transportation_logistics": ["نقل", "لوجستي", "توصيل", "شحن", "مواصلات", "سائق", "أسطول", "مستودع"],
    "energy_renewable": ["طاقة", "شمسي", "كهرباء", "نفط", "غاز", "متجدد", "بيئة", "استدامة"],
    "tourism_hospitality": ["سياحة", "فندق", "منتجع", "سفر", "ترفيه", "ثقافة", "تراث", "متحف"],
    "fashion_beauty": ["أزياء", "ملابس", "عطور", "تجميل", "مكياج", "عناية", "مجوهرات", "ساعات"],
    "fintech_financial": ["بنك", "مالي", "دفع", "تمويل", "استثمار", "تأمين", "عملة", "قرض"],
    "cleaning_maintenance": ["تنظيف", "غسيل", "صيانة", "نظافة", "مكافحة", "حشرات"],
    "automotive": ["سيارة", "مركبة", "ورشة", "غيار", "تأجير", "كهربائي"],
    "media_entertainment": ["إعلام", "ترفيه", "فيديو", "موسيقى", "ألعاب", "محتوى", "نشر", "إعلان"],
    "sports_fitness": ["رياضة", "لياقة", "نادي", "جيم", "تدريب", "بدني", "صحي"],
    "robotics_automation": ["روبوت", "مكنسة", "آلي", "أتمتة", "ذكي", "جهاز", "صناعي", "معدات"],
    "logistics_delivery": ["توصيل", "شحن", "لوجستي", "نقل", "طرود", "بريد", "مندوب"],
}


def get_sectors_for_project(project_name: str, project_description: str) -> list:
    """Analyze project name and description to determine relevant sectors."""
    import re

    text = f"{project_name} {project_description}".lower()
    matched_sectors = []
    scores = []

    for sector_name, sector_data in SECTOR_REFERENCES.items():
        if sector_name == "general_sme":
            continue
        score = 0
        for keyword in sector_data["keywords"]:
            occurrences = len(re.findall(re.escape(keyword), text))
            score += occurrences
        arabic_keywords = ARABIC_KEYWORD_MAP.get(sector_name, [])
        for keyword in arabic_keywords:
            occurrences = len(re.findall(keyword, text))
            score += occurrences
        if score > 0:
            scores.append((score, sector_name))

    scores.sort(key=lambda x: -x[0])
    matched_sectors = [name for _, name in scores[:3]]

    if not matched_sectors:
        matched_sectors = ["general_sme"]

    return matched_sectors


def get_references_for_project(project_name: str, project_description: str) -> list:
    """Get curated references matching the project's sector(s)."""
    sectors = get_sectors_for_project(project_name, project_description)
    seen_urls = set()
    references = []

    for sector in sectors:
        if sector in SECTOR_REFERENCES:
            for ref in SECTOR_REFERENCES[sector]["references"]:
                url = ref.get("url", "").rstrip("/")
                if url not in seen_urls:
                    seen_urls.add(url)
                    references.append(dict(ref))

    if not references:
        references = [dict(r) for r in SECTOR_REFERENCES.get("general_sme", {}).get("references", [])]

    return references
