classDiagram
    direction TB

    %% ==========================================
    %% PACKAGE: K8s API Definitions (Blueprints)
    %% ==========================================
    namespace API_Blueprints {
        class ClusterBlueprint {
            <<Kind: ClusterBlueprint, Short: cbp>>
            Description: Generic cluster request
            ---
            +spec.infraBlueprintRef : string
            +spec.kubernetesVersion : string
            +spec.workerPools : List~GenericPoolReq~
        }

        class InfraBlueprint {
            <<Kind: InfraBlueprint, Short: ibp>>
            Description: Manages quotas and provider ref
            ---
            +spec.quotaLimits : ResourceList
            +status.quotaUsed : ResourceList
            +spec.providerRef : TypedLocalObjectReference
        }

        class VsphereBlueprint {
            <<Kind: VsphereBlueprint, Short: vbp>>
            Description: Concrete vSphere details
            ---
            +spec.vcenterURL : string
            +spec.datacenterID : string
            +spec.networkIDs : List~string~
        }

        class HarvesterBlueprint {
            <<Kind: HarvesterBlueprint, Short: hbp>>
            Description: Concrete Harvester details
            ---
            +spec.harvesterURL : string
            +spec.vmNamespace : string
            +spec.imageName : string
        }

        class AzureBlueprint {
             <<Kind: AzureBlueprint, Short: abp>>
             Description: Future Azure details
        }
    }

    %% Relationships between Blueprints
    ClusterBlueprint --> InfraBlueprint : 1. References by Name
    note for InfraBlueprint "The providerRef is polymorphic.\nIt points to ANY ProviderBlueprint Kind\n(vbp, hbp, or abp)."
    InfraBlueprint ..> VsphereBlueprint : 2. Dynamically references Kind=vbp
    InfraBlueprint ..> HarvesterBlueprint : 2. Dynamically references Kind=hbp
    InfraBlueprint ..> AzureBlueprint : 2. Dynamically references Kind=abp


    %% ==========================================
    %% PACKAGE: Controller (Orchestration)
    %% ==========================================
    namespace Controller_Layer {
        class RIGController {
            Description: The brain. Watches CBPs, checks IBP quotas.
            ---
            +Reconcile(request)
        }
    }

    RIGController "watches" --> ClusterBlueprint
    RIGController "reads & checks quota" --> InfraBlueprint


    %% ==========================================
    %% PACKAGE: Builders & Strategies (Generation)
    %% ==========================================
    namespace Generation_Layer {
        class MasterValuesBuilder {
            Description: Knows generic Helm structure.
            ---
            -strategy : ProviderStrategy
            +BuildHelmValues(cbp, ibp) Map
        }

        class ProviderStrategy {
            <<Interface>>
            Description: Contract for isolated provider logic.
            ---
            +GenerateNodePools(genericPools, providerBP) List~Any~
            +GetGlobalOverrides(providerBP) Map
            +PerformPreFlight(ctx, providerBP) Error
        }

        class VsphereStrategy {
            Description: Specialist VBP to Helm translation.
            ---
            +GenerateNodePools(...)
        }

        class HarvesterStrategy {
            Description: Specialist HBP to Helm translation.
            ---
            +GenerateNodePools(...)
            +PerformPreFlight(...)
        }
    }

    %% Controller orchestrates builders
    note for RIGController "1. Reads IBP.providerRef.Kind\n2. Instantiates correct Strategy (e.g. VsphereStrategy)\n3. Injects Strategy into MasterBuilder\n4. Calls MasterBuilder.Build()"

    RIGController "configures & calls" --> MasterValuesBuilder

    %% Master Builder uses the interface
    MasterValuesBuilder o--> ProviderStrategy : Injected Dependency

    %% Realization of strategies
    ProviderStrategy <|.. VsphereStrategy : Implements
    ProviderStrategy <|.. HarvesterStrategy : Implements

    %% Strategies read their specific blueprints
    VsphereStrategy ..> VsphereBlueprint : Reads config to map data
    HarvesterStrategy ..> HarvesterBlueprint : Reads config to map data