Private/Get-PstComplexitySchema.ps1

function Get-PstComplexitySchema {
    <#
    .SYNOPSIS
        Returns the complexity level schema definitions for PowerShell code generation.

    .DESCRIPTION
        Defines the features, patterns, and structures included at each complexity level
        (Basic, Standard, Advanced) for functions, scripts, and modules. This schema drives
        the intelligent code generation system.

    .PARAMETER Complexity
        The complexity level to retrieve schema for: Basic, Standard, or Advanced.
        If not specified, returns all schemas.

    .PARAMETER Type
        The type of artifact: Function, Script, or Module.
        If not specified, returns schema for all types.

    .EXAMPLE
        Get-PstComplexitySchema -Complexity Standard -Type Function
        Returns the Standard complexity schema for functions.

    .EXAMPLE
        Get-PstComplexitySchema
        Returns all complexity schemas for all types.

    .NOTES
        Version: 1.0
        Author: numidia
        Creation Date: 2025-12-01
        Purpose: Define progressive PowerShell learning levels
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $false)]
        [ValidateSet('Basic', 'Standard', 'Advanced')]
        [string]$Complexity,

        [Parameter(Mandatory = $false)]
        [ValidateSet('Function', 'Script', 'Module')]
        [string]$Type
    )

    begin {
        Write-Debug "Begin '$($MyInvocation.MyCommand.Name)' at '$(Get-Date)'"

        # Define the complete complexity schema
        $schema = @{
            Basic = @{
                Function = @{
                    Description = "Simple function for beginners learning PowerShell basics"
                    CommentHelp = @{
                        Sections = @('Synopsis', 'Description', 'Parameter', 'Example')
                        ExampleCount = 1
                        IncludeNotes = $false
                        IncludeLinks = $false
                    }
                    CmdletBinding = @{
                        Enabled = $false
                        SupportsShouldProcess = $false
                        DefaultParameterSetName = $null
                    }
                    Parameters = @{
                        ValidationLevel = 'Basic'
                        SupportsPipeline = $false
                        SupportsPosition = $false
                        SupportsHelpMessages = $false
                        ValidateAttributes = @('ValidateNotNullOrEmpty', 'ValidateRange')
                    }
                    Structure = @{
                        BeginBlock = $false
                        ProcessBlock = $true
                        EndBlock = $false
                    }
                    ErrorHandling = @{
                        Level = 'Basic'
                        UseTryCatch = $true
                        UseSpecificExceptions = $false
                        UseErrorRecord = $false
                        UseThrowTerminating = $false
                    }
                    Logging = @{
                        WriteVerbose = $true
                        WriteDebug = $false
                        WriteInformation = $false
                        WriteProgress = $false
                    }
                    Output = @{
                        TypeConstraint = $false
                        UseWriteOutput = $true
                    }
                    Features = @()
                }
                Script = @{
                    Description = "Simple script for basic automation tasks"
                    Header = @{
                        IncludeRequires = $false
                        IncludeUsing = $false
                        IncludeCommentHeader = $true
                    }
                    Parameters = @{
                        UseParamBlock = $true
                        ValidationLevel = 'Basic'
                    }
                    Structure = @{
                        Sections = @('Parameters', 'MainLogic')
                    }
                    ErrorHandling = @{
                        Level = 'Basic'
                        UseTryCatch = $true
                    }
                    Logging = @{
                        WriteVerbose = $true
                        WriteHost = $true
                    }
                    Features = @()
                }
                Module = @{
                    Description = "Simple module structure for learning module basics"
                    Structure = @{
                        Directories = @()
                        Files = @('ModuleName.psd1', 'ModuleName.psm1')
                    }
                    Manifest = @{
                        Author = $true
                        Description = $true
                        Version = $true
                        RootModule = $true
                        FunctionsToExport = $true
                        MinimalFields = $true
                    }
                    RootModule = @{
                        DotSourcePattern = 'Simple'
                        ExportFunctions = 'Explicit'
                    }
                    Documentation = @{
                        IncludeReadme = $false
                    }
                    Testing = @{
                        IncludeTests = $false
                    }
                    Features = @()
                }
            }

            Standard = @{
                Function = @{
                    Description = "Well-structured function following PowerShell best practices"
                    CommentHelp = @{
                        Sections = @('Synopsis', 'Description', 'Parameter', 'Example', 'Notes', 'Link')
                        ExampleCount = 2
                        IncludeNotes = $true
                        IncludeLinks = $true
                    }
                    CmdletBinding = @{
                        Enabled = $true
                        SupportsShouldProcess = $true
                        DefaultParameterSetName = $null
                    }
                    Parameters = @{
                        ValidationLevel = 'Standard'
                        SupportsPipeline = $true
                        SupportsPosition = $true
                        SupportsHelpMessages = $true
                        ValidateAttributes = @('ValidateNotNullOrEmpty', 'ValidateRange', 'ValidateSet', 'ValidateScript', 'ValidatePattern')
                    }
                    Structure = @{
                        BeginBlock = $true
                        ProcessBlock = $true
                        EndBlock = $true
                    }
                    ErrorHandling = @{
                        Level = 'Standard'
                        UseTryCatch = $true
                        UseSpecificExceptions = $true
                        UseErrorRecord = $false
                        UseThrowTerminating = $false
                    }
                    Logging = @{
                        WriteVerbose = $true
                        WriteDebug = $true
                        WriteInformation = $true
                        WriteProgress = $false
                    }
                    Output = @{
                        TypeConstraint = $false
                        UseWriteOutput = $true
                    }
                    Features = @('ShouldProcess', 'PipelineSupport')
                }
                Script = @{
                    Description = "Production-ready script with proper structure and error handling"
                    Header = @{
                        IncludeRequires = $true
                        IncludeUsing = $false
                        IncludeCommentHeader = $true
                    }
                    Parameters = @{
                        UseParamBlock = $true
                        ValidationLevel = 'Standard'
                        UseCmdletBinding = $true
                    }
                    Structure = @{
                        Sections = @('Header', 'Parameters', 'Configuration', 'MainLogic', 'ErrorHandling')
                    }
                    ErrorHandling = @{
                        Level = 'Standard'
                        UseTryCatch = $true
                        UseSpecificExceptions = $true
                    }
                    Logging = @{
                        WriteVerbose = $true
                        WriteInformation = $true
                        WriteHost = $false
                    }
                    Features = @('ParameterValidation', 'Logging')
                }
                Module = @{
                    Description = "Professional module structure with testing and documentation"
                    Structure = @{
                        Directories = @('Public', 'Private', 'tests')
                        Files = @('ModuleName.psd1', 'ModuleName.psm1', 'README.md', 'tests\ModuleName.Tests.ps1')
                    }
                    Manifest = @{
                        Author = $true
                        Description = $true
                        Version = $true
                        RootModule = $true
                        FunctionsToExport = $true
                        MinimalFields = $false
                        GUID = $true
                        PowerShellVersion = $true
                        Tags = $true
                        ProjectUri = $true
                    }
                    RootModule = @{
                        DotSourcePattern = 'PublicPrivate'
                        ExportFunctions = 'Automatic'
                    }
                    Documentation = @{
                        IncludeReadme = $true
                        ReadmeLevel = 'Standard'
                    }
                    Testing = @{
                        IncludeTests = $true
                        TestStructure = 'Single'
                    }
                    Features = @('PublicPrivateSeparation', 'BasicTesting', 'Documentation')
                }
            }

            Advanced = @{
                Function = @{
                    Description = "Enterprise-grade function with comprehensive features and optimization"
                    CommentHelp = @{
                        Sections = @('Synopsis', 'Description', 'Parameter', 'Example', 'Notes', 'Link', 'Inputs', 'Outputs')
                        ExampleCount = 3
                        IncludeNotes = $true
                        IncludeLinks = $true
                    }
                    CmdletBinding = @{
                        Enabled = $true
                        SupportsShouldProcess = $true
                        DefaultParameterSetName = 'Default'
                        SupportsParameterSets = $true
                    }
                    Parameters = @{
                        ValidationLevel = 'Advanced'
                        SupportsPipeline = $true
                        SupportsPosition = $true
                        SupportsHelpMessages = $true
                        SupportsParameterSets = $true
                        SupportsDynamicParameters = $false
                        ValidateAttributes = @('ValidateNotNullOrEmpty', 'ValidateRange', 'ValidateSet', 'ValidateScript', 'ValidatePattern', 'ValidateCount', 'ValidateLength')
                    }
                    Structure = @{
                        BeginBlock = $true
                        ProcessBlock = $true
                        EndBlock = $true
                    }
                    ErrorHandling = @{
                        Level = 'Advanced'
                        UseTryCatch = $true
                        UseSpecificExceptions = $true
                        UseErrorRecord = $true
                        UseThrowTerminating = $true
                    }
                    Logging = @{
                        WriteVerbose = $true
                        WriteDebug = $true
                        WriteInformation = $true
                        WriteProgress = $true
                    }
                    Output = @{
                        TypeConstraint = $true
                        UseWriteOutput = $true
                        UseOutputType = $true
                    }
                    Features = @('ShouldProcess', 'PipelineSupport', 'ParameterSets', 'PerformanceOptimization', 'ComprehensiveErrorHandling')
                }
                Script = @{
                    Description = "Enterprise-grade script with advanced features, logging, and monitoring"
                    Header = @{
                        IncludeRequires = $true
                        IncludeUsing = $true
                        IncludeCommentHeader = $true
                    }
                    Parameters = @{
                        UseParamBlock = $true
                        ValidationLevel = 'Advanced'
                        UseCmdletBinding = $true
                        SupportsParameterSets = $true
                    }
                    Structure = @{
                        Sections = @('Header', 'Parameters', 'Configuration', 'Initialization', 'Functions', 'MainLogic', 'ErrorHandling', 'Cleanup')
                    }
                    ErrorHandling = @{
                        Level = 'Advanced'
                        UseTryCatch = $true
                        UseSpecificExceptions = $true
                        UseErrorRecord = $true
                    }
                    Logging = @{
                        WriteVerbose = $true
                        WriteInformation = $true
                        WriteDebug = $true
                        UseTranscript = $true
                        WriteHost = $false
                    }
                    Features = @('ParameterValidation', 'ComprehensiveLogging', 'PerformanceMonitoring', 'HelperFunctions')
                }
                Module = @{
                    Description = "Enterprise-grade module with full CI/CD, comprehensive testing, and documentation"
                    Structure = @{
                        Directories = @('Public', 'Private', 'Classes', 'Resources', 'tests\Unit', 'tests\Integration', 'docs')
                        Files = @(
                            'ModuleName.psd1',
                            'ModuleName.psm1',
                            'README.md',
                            'CHANGELOG.md',
                            'build.ps1',
                            '.gitignore',
                            'tests\Unit\ModuleName.Tests.ps1',
                            'tests\Integration\ModuleName.Integration.Tests.ps1'
                        )
                    }
                    Manifest = @{
                        Author = $true
                        Description = $true
                        Version = $true
                        RootModule = $true
                        FunctionsToExport = $true
                        MinimalFields = $false
                        GUID = $true
                        PowerShellVersion = $true
                        Tags = $true
                        ProjectUri = $true
                        LicenseUri = $true
                        IconUri = $false
                        ReleaseNotes = $true
                        RequiredModules = $true
                    }
                    RootModule = @{
                        DotSourcePattern = 'Advanced'
                        ExportFunctions = 'Automatic'
                        IncludeClasses = $true
                    }
                    Documentation = @{
                        IncludeReadme = $true
                        ReadmeLevel = 'Advanced'
                        IncludeChangelog = $true
                        IncludeFunctionDocs = $true
                    }
                    Testing = @{
                        IncludeTests = $true
                        TestStructure = 'UnitIntegration'
                        CodeCoverageTarget = 90
                    }
                    Build = @{
                        IncludeBuildScript = $true
                        IncludeGitIgnore = $true
                    }
                    Features = @('PublicPrivateSeparation', 'ClassSupport', 'ComprehensiveTesting', 'FullDocumentation', 'BuildAutomation')
                }
            }
        }
    }

    process {
        try {
            # Filter based on parameters
            if ($Complexity -and $Type) {
                Write-Verbose "Returning schema for Complexity: '$Complexity', Type: '$Type'"
                return $schema[$Complexity][$Type]
            }
            elseif ($Complexity) {
                Write-Verbose "Returning all schemas for Complexity: '$Complexity'"
                return $schema[$Complexity]
            }
            elseif ($Type) {
                Write-Verbose "Returning '$Type' schemas for all complexity levels"
                $result = @{}
                foreach ($level in @('Basic', 'Standard', 'Advanced')) {
                    $result[$level] = $schema[$level][$Type]
                }
                return $result
            }
            else {
                Write-Verbose "Returning complete complexity schema"
                return $schema
            }
        }
        catch {
            Write-Error "Failed to retrieve complexity schema: $($_.Exception.Message)"
            throw
        }
    }

    end {
        Write-Debug "End '$($MyInvocation.MyCommand.Name)' at '$(Get-Date)'"
    }
}