"""
Metadata Profiles with Value Variants

This module contains predefined metadata profiles that simulate realistic
cloud resource metadata with common variants, misspellings, and inconsistencies
found in real-world CloudZero customer environments.

Each profile contains canonical values and their realistic variants including:
- Different naming conventions (hyphens, underscores, camelCase)
- Common abbreviations
- Typical misspellings and typos
- Case variations
"""

METADATA_PROFILES = {
    "regions": {
        "us-east-1": {"weight": 0.6},
        "us-west-2": {"weight": 0.3},
        "eu-west-1": {"weight": 0.1},
    },
    "products": {
        "DataPulse": {
            "variants": [
                "data-pulse",
                "data_pulse",
                "datapulse",
                "dp",
                "datapulse_",
                "data-pules",
                "datapluse",
            ],
            "tag_variants": ["product", "prod", "Product"],
        },
        "MetricFlow": {
            "variants": [
                "metric-flow",
                "metric_flow",
                "metricflow",
                "mf",
                "metricfow",
                "metric-flo",
                "metricflo",
            ],
            "tag_variants": ["product", "prod", "Product"],
        },
        "InsightScope": {
            "variants": [
                "insight-scope",
                "insight_scope",
                "insightscope",
                "is",
                "insigt-scope",
                "insight-scop",
            ],
            "tag_variants": ["product", "prod", "Product"],
        },
        "TaskFlow": {
            "variants": [
                "task-flow",
                "task_flow",
                "taskflow",
                "tf",
                "taksflow",
                "task-fow",
                "taskflo",
            ],
            "tag_variants": ["product", "prod", "Product"],
        },
        "HelpStream": {
            "variants": [
                "help-stream",
                "help_stream",
                "helpstream",
                "hs",
                "help-stram",
                "helpstrem",
            ],
            "tag_variants": ["product", "prod", "Product"],
        },
        "SupportSync": {
            "variants": [
                "support-sync",
                "support_sync",
                "supportsync",
                "ss",
                "suport-sync",
                "support-synk",
            ],
            "tag_variants": ["product", "prod", "Product"],
        },
    },
    "features": {
        "Pulse Analytics Dashboard": {
            "variants": [
                "pulse-analytics",
                "pulse_analytics",
                "pad",
                "pulse-analytic",
                "pulseanalytics",
                "pulse-analytics-dash",
            ],
            "tag_variants": ["feature", "feat", "Feature"],
        },
        "Alert Sense Detector": {
            "variants": [
                "alert-sense",
                "alert_sense",
                "asd",
                "alter-sense",
                "alertsense",
                "alert-detector",
            ],
            "tag_variants": ["feature", "feat", "Feature"],
        },
        "Report Craft Studio": {
            "variants": [
                "report-craft",
                "report_craft",
                "rcs",
                "reportcraft",
                "report-caft",
                "report-studio",
            ],
            "tag_variants": ["feature", "feat", "Feature"],
        },
        "Predict IQ Engine": {
            "variants": [
                "predict-iq",
                "predict_iq",
                "piq",
                "prediciq",
                "predict-iq_",
                "predict-engine",
            ],
            "tag_variants": ["feature", "feat", "Feature"],
        },
        "Data Bridge Connector": {
            "variants": [
                "data-bridge",
                "data_bridge",
                "dbc",
                "databridge",
                "data-brige",
                "data-connector",
            ],
            "tag_variants": ["feature", "feat", "Feature"],
        },
        "Access Matrix Control": {
            "variants": [
                "access-matrix",
                "access_matrix",
                "amc",
                "accessmatrix",
                "acess-matrix",
                "access-control",
            ],
            "tag_variants": ["feature", "feat", "Feature"],
        },
        "Query Speak Interface": {
            "variants": [
                "query-speak",
                "query_speak",
                "qsi",
                "queryspeak",
                "query-spek",
                "query-interface",
            ],
            "tag_variants": ["feature", "feat", "Feature"],
        },
        "Clean Swift Processor": {
            "variants": [
                "clean-swift",
                "clean_swift",
                "csp",
                "cleanswift",
                "clean-swft",
                "swift-processor",
            ],
            "tag_variants": ["feature", "feat", "Feature"],
        },
        "Chart Share Platform": {
            "variants": [
                "chart-share",
                "chart_share",
                "csp",
                "chartshare",
                "chart-shar",
                "chart-platform",
            ],
            "tag_variants": ["feature", "feat", "Feature"],
        },
    },
    "teams": {
        "BitKeepers": {
            "variants": [
                "bit-keepers",
                "bit_keepers",
                "bitkeepers",
                "bk",
                "bitkepers",
                "bit-kepers",
            ],
            "tag_variants": ["team", "Team"],
        },
        "ByteBuilders": {
            "variants": [
                "byte-builders",
                "byte_builders",
                "bytebuilders",
                "bb",
                "byte-buidlers",
                "bytebuilder",
            ],
            "tag_variants": ["team", "Team"],
        },
        "LaunchPad": {
            "variants": [
                "launch-pad",
                "launch_pad",
                "launchpad",
                "lp",
                "lauch-pad",
                "launch-pads",
            ],
            "tag_variants": ["team", "Team"],
        },
        "CodeFleet": {
            "variants": [
                "code-fleet",
                "code_fleet",
                "codefleet",
                "cf",
                "code-flet",
                "code-fleet-team",
            ],
            "tag_variants": ["team", "Team"],
        },
        "DataDragons": {
            "variants": [
                "data-dragons",
                "data_dragons",
                "datadragons",
                "dd",
                "data-dragns",
                "data-dragon",
            ],
            "tag_variants": ["team", "Team"],
        },
        "CloudNinjas": {
            "variants": [
                "cloud-ninjas",
                "cloud_ninjas",
                "cloudninjas",
                "cn",
                "clound-ninjas",
                "cloud-ninja",
            ],
            "tag_variants": ["team", "Team"],
        },
    },
    "business_units": {
        "Engineering": {
            "variants": [
                "engineering",
                "eng",
                "ENGINEERING",
                "enginering",
                "engieering",
                "engineer",
            ],
            "tag_variants": [
                "business_unit",
                "bu",
                "BusinessUnit",
            ],
        },
        "Product": {
            "variants": [
                "product",
                "prod",
                "PRODUCT",
                "porduct",
                "prodcut",
                "products",
            ],
            "tag_variants": [
                "business_unit",
                "bu",
                "BusinessUnit",
            ],
        },
        "Marketing": {
            "variants": [
                "marketing",
                "mktg",
                "MARKETING",
                "markting",
                "marketng",
                "market",
            ],
            "tag_variants": [
                "business_unit",
                "bu",
                "BusinessUnit",
            ],
        },
        "Sales": {
            "variants": ["sales", "sls", "SALES", "sale", "saels", "sales-team"],
            "tag_variants": [
                "business_unit",
                "bu",
                "BusinessUnit",
            ],
        },
        "Support": {
            "variants": [
                "support",
                "sup",
                "SUPPORT",
                "suport",
                "supprt",
                "customer-support",
            ],
            "tag_variants": [
                "business_unit",
                "bu",
                "BusinessUnit",
            ],
        },
        "Operations": {
            "variants": [
                "operations",
                "ops",
                "OPERATIONS",
                "operatons",
                "operation",
                "devops",
            ],
            "tag_variants": [
                "business_unit",
                "bu",
                "BusinessUnit",
            ],
        },
    },
    "cost_centers": {
        "CC-1001": {
            "variants": ["cc-1001", "CC1001", "cc_1001", "cc-001", "cc1001", "CC-1001"],
            "tag_variants": ["cost_center", "cc", "CostCenter"],
        },
        "CC-1002": {
            "variants": ["cc-1002", "CC1002", "cc_1002", "cc-002", "cc1002", "CC-1002"],
            "tag_variants": ["cost_center", "cc", "CostCenter"],
        },
        "CC-1003": {
            "variants": ["cc-1003", "CC1003", "cc_1003", "cc-003", "cc1003", "CC-1003"],
            "tag_variants": ["cost_center", "cc", "CostCenter"],
        },
        "CC-2001": {
            "variants": ["cc-2001", "CC2001", "cc_2001", "cc-201", "cc2001", "CC-2001"],
            "tag_variants": ["cost_center", "cc", "CostCenter"],
        },
        "CC-2002": {
            "variants": ["cc-2002", "CC2002", "cc_2002", "cc-202", "cc2002", "CC-2002"],
            "tag_variants": ["cost_center", "cc", "CostCenter"],
        },
        "CC-3001": {
            "variants": ["cc-3001", "CC3001", "cc_3001", "cc-301", "cc3001", "CC-3001"],
            "tag_variants": ["cost_center", "cc", "CostCenter"],
        },
    },
    "environments": {
        "production": {
            "variants": [
                "prod",
                "production",
                "prd",
                "PROD",
                "prodction",
                "porduction",
                "prod-env",
            ],
            "tag_variants": ["environment", "env", "Environment", "Env"],
            "weight": 0.7,
        },
        "staging": {
            "variants": [
                "stage",
                "staging",
                "stg",
                "STAGING",
                "stagng",
                "staginng",
                "stage-env",
            ],
            "tag_variants": ["environment", "env", "Environment", "Env"],
            "weight": 0.2,
        },
        "development": {
            "variants": [
                "dev",
                "development",
                "devel",
                "DEV",
                "developement",
                "dev_",
                "dev-env",
            ],
            "tag_variants": ["environment", "env", "Environment", "Env"],
            "weight": 0.1,
        },
        "testing": {
            "variants": [
                "test",
                "testing",
                "tst",
                "TEST",
                "testin",
                "test_",
                "qa",
                "test-env",
            ],
            "tag_variants": ["environment", "env", "Environment", "Env"],
            "weight": 0.05,
        },
        "sandbox": {
            "variants": [
                "sandbox",
                "sbx",
                "SANDBOX",
                "sand-box",
                "sndbox",
                "sb",
                "sandbox-env",
            ],
            "tag_variants": ["environment", "env", "Environment", "Env"],
            "weight": 0.05,
        },
    },
    "cloud_account_patterns": {
        "pattern_1": {
            "formats": [
                "{environment}-{product}",
                "{product}-{environment}",
                "{environment}-{product}-{suffix}",
                "{product}-{suffix}",
            ],
            "suffixes": ["main", "primary", "01", "02", "core", "central"],
            "products": [
                "analytics",
                "platform",
                "data",
                "api",
                "core",
                "web",
                "mobile",
                "backend",
            ],
            "environments": ["prod", "staging", "dev", "test", "sandbox"],
        },
        "pattern_2": {
            "formats": [
                "{environment}-{product}-{suffix}",
                "{product}-{environment}-{suffix}",
                "{suffix}-{environment}-{product}",
                "{product}-{suffix}",
            ],
            "suffixes": ["hub", "workspace", "env", "zone", "01", "02", "central"],
            "products": [
                "analytics",
                "platform",
                "data",
                "api",
                "core",
                "web",
                "mobile",
                "backend",
            ],
            "environments": ["prod", "staging", "dev", "test", "sandbox"],
        },
        "pattern_3": {
            "formats": [
                "{environment}-{product}-{numeric}",
                "{product}-{environment}-{numeric}",
                "{environment}-{product}-{suffix}",
                "{numeric}-{product}",
            ],
            "suffixes": ["123456", "789012", "456789", "workspace", "env", "zone"],
            "products": [
                "analytics",
                "platform",
                "data",
                "api",
                "core",
                "web",
                "mobile",
                "backend",
            ],
            "environments": ["prod", "staging", "dev", "test", "sandbox"],
            "numerics": ["123456", "789012", "456789", "234567", "567890", "345678"],
        },
    },
    "account_distribution_strategy": {
        "production_heavy": {
            "weight": 0.45,
            "keywords": ["prod", "production", "main", "primary", "core"],
        },
        "staging_medium": {
            "weight": 0.25,
            "keywords": ["staging", "stage", "platform", "hub"],
        },
        "development_light": {
            "weight": 0.20,
            "keywords": ["dev", "development", "test", "testing"],
        },
        "sandbox_minimal": {
            "weight": 0.10,
            "keywords": ["sandbox", "demo", "experimental", "workspace"],
        },
    },
}


def get_profile(profile_name: str) -> dict:
    """Get a specific metadata profile by name.

    Args:
        profile_name: Name of the profile (e.g., 'products', 'teams')

    Returns:
        Dictionary containing the profile data

    Raises:
        KeyError: If profile_name doesn't exist
    """
    if profile_name not in METADATA_PROFILES:
        available = list(METADATA_PROFILES.keys())
        raise KeyError(
            f"Profile '{profile_name}' not found. Available profiles: {available}"
        )

    return METADATA_PROFILES[profile_name]


def list_profiles() -> list:
    """Get list of all available metadata profile names.

    Returns:
        List of profile names
    """
    return list(METADATA_PROFILES.keys())


def get_profile_values(profile_name: str) -> list:
    """Get list of canonical values for a profile.

    Args:
        profile_name: Name of the profile

    Returns:
        List of canonical values in the profile
    """
    profile = get_profile(profile_name)
    return list(profile.keys())


def get_profile_info(profile_name: str) -> dict:
    """Get detailed information about a profile.

    Args:
        profile_name: Name of the profile

    Returns:
        Dictionary with profile statistics and details
    """
    profile = get_profile(profile_name)

    total_variants = 0
    canonical_values = list(profile.keys())

    for canonical_value in canonical_values:
        if "variants" in profile[canonical_value]:
            total_variants += len(profile[canonical_value]["variants"])

    return {
        "name": profile_name,
        "canonical_count": len(canonical_values),
        "total_variants": total_variants,
        "avg_variants_per_value": round(total_variants / len(canonical_values), 1)
        if canonical_values
        else 0,
        "canonical_values": canonical_values,
    }


def get_profile_weights(profile_name: str) -> dict:
    """Get weights for profile values (for regions and environments).

    Args:
        profile_name: Name of the profile

    Returns:
        Dictionary mapping canonical values to weights
    """
    profile = get_profile(profile_name)
    weights = {}

    for canonical_value, config in profile.items():
        if "weight" in config:
            weights[canonical_value] = config["weight"]
        else:
            # Default equal weight if not specified
            weights[canonical_value] = 1.0 / len(profile)

    return weights


def get_tag_variants(profile_name: str, canonical_value: str) -> list:
    """Get tag key variants for a specific profile value.

    Args:
        profile_name: Name of the profile
        canonical_value: Canonical value within the profile

    Returns:
        List of tag key variants, or empty list if none defined
    """
    profile = get_profile(profile_name)

    if canonical_value not in profile:
        return []

    return profile[canonical_value].get("tag_variants", [])


def get_cloud_account_patterns() -> dict:
    """Get cloud account patterns configuration.

    Returns:
        Dictionary containing cloud account patterns for different providers
    """
    return METADATA_PROFILES["cloud_account_patterns"]


def get_account_distribution_strategy() -> dict:
    """Get account distribution strategy configuration.

    Returns:
        Dictionary containing distribution weights and keywords
    """
    return METADATA_PROFILES["account_distribution_strategy"]
