Public/Initialize-DLPWorkspace.ps1

function Initialize-DLPWorkspace {
    <#
    .SYNOPSIS
        Initializes a DLP workspace by copying template files to the current directory.
    
    .DESCRIPTION
        Creates the necessary folder structure and copies template configuration and content
        files from the module to your working directory. This allows you to customize
        policy tips, email notifications, and configuration files for your environment.
        
        The following directories will be created:
        - Config/ - CSV configuration files for bulk updates
        - Content/ - HTML templates for policy tips and email notifications
          - PolicyTips/ - Policy tip HTML files
          - EmailBodies/ - Email body HTML files
        
        Files are copied from the module's Templates directory to your current location.
        Existing files will not be overwritten unless -Force is specified.
    
    .PARAMETER Path
        Optional. The path where the workspace should be initialized.
        Default: Current directory (Get-Location)
    
    .PARAMETER Force
        Overwrite existing files if they already exist.
        Default: $false (preserves existing customizations)
    
    .PARAMETER SkipConfig
        Skip copying the Config directory and files.
        Useful if you only need to refresh Content templates.
    
    .PARAMETER SkipContent
        Skip copying the Content directory and files.
        Useful if you only need to refresh Config templates.
    
    .OUTPUTS
        PSCustomObject with properties:
        - Success (bool): Whether initialization succeeded
        - Path (string): Path where workspace was initialized
        - CreatedDirectories (string[]): List of directories created
        - CopiedFiles (string[]): List of files copied
        - SkippedFiles (string[]): List of files skipped (already exist)
    
    .EXAMPLE
        Initialize-DLPWorkspace
        
        Creates Config/ and Content/ folders in the current directory with template files.
    
    .EXAMPLE
        Initialize-DLPWorkspace -Path "C:\DLP\MyProject"
        
        Creates workspace in the specified directory.
    
    .EXAMPLE
        Initialize-DLPWorkspace -Force
        
        Overwrites any existing files with fresh templates from the module.
    
    .EXAMPLE
        Initialize-DLPWorkspace -SkipContent
        
        Only copies Config files, skips Content directory.
    
    .NOTES
        Run this command once when starting a new DLP project.
        Customize the copied files to match your organization's requirements.
        The original templates remain in the module and can be re-copied anytime.
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory = $false)]
        [string]$Path = (Get-Location).Path,
        
        [Parameter(Mandatory = $false)]
        [switch]$Force,
        
        [Parameter(Mandatory = $false)]
        [switch]$SkipConfig,
        
        [Parameter(Mandatory = $false)]
        [switch]$SkipContent
    )
    
    Write-ColorOutput "`n$('═' * 80)" -Type Header
    Write-ColorOutput " Initialize DLP Workspace" -Type Header
    Write-ColorOutput "$('═' * 80)`n" -Type Header
    
    # Get module root directory
    $moduleRoot = Split-Path -Path $PSScriptRoot -Parent
    $templatesPath = Join-Path $moduleRoot "Templates"
    
    if (-not (Test-Path $templatesPath)) {
        Write-ColorOutput "✗ Error: Templates directory not found in module: $templatesPath" -Type Error
        return @{
            Success = $false
            Path = $Path
            Error = "Templates directory not found in module"
        }
    }
    
    # Resolve target path
    $targetPath = Resolve-Path -Path $Path -ErrorAction SilentlyContinue
    if (-not $targetPath) {
        $targetPath = $Path
    }
    
    Write-ColorOutput "Initializing workspace at: $targetPath`n" -Type Info
    
    # Initialize result object
    $result = @{
        Success = $true
        Path = $targetPath
        CreatedDirectories = @()
        CopiedFiles = @()
        SkippedFiles = @()
    }
    
    try {
        # Define directory structure
        $directories = @()
        if (-not $SkipConfig) {
            $directories += @(
                'Config'
                'Config\examples'
            )
        }
        if (-not $SkipContent) {
            $directories += @(
                'Content'
                'Content\PolicyTips'
                'Content\EmailBodies'
            )
        }
        
        # Create directories
        Write-ColorOutput "Creating directory structure..." -Type Info
        foreach ($dir in $directories) {
            $dirPath = Join-Path $targetPath $dir
            if (-not (Test-Path $dirPath)) {
                if ($PSCmdlet.ShouldProcess($dirPath, "Create Directory")) {
                    New-Item -Path $dirPath -ItemType Directory -Force | Out-Null
                    $result.CreatedDirectories += $dir
                    Write-ColorOutput " ✓ Created: $dir" -Type Success
                }
            }
            else {
                Write-ColorOutput " - Exists: $dir" -Type Info
            }
        }
        
        Write-Host ""
        
        # Copy files
        Write-ColorOutput "Copying template files..." -Type Info
        
        # Define files to copy
        $filesToCopy = @()
        
        if (-not $SkipConfig) {
            $filesToCopy += @(
                @{ Source = 'Config\update-config.csv'; Dest = 'Config\update-config.csv' }
                @{ Source = 'Config\README.md'; Dest = 'Config\README.md' }
                @{ Source = 'Config\QUICK-START.md'; Dest = 'Config\QUICK-START.md' }
                @{ Source = 'Config\examples\wildcard-example.csv'; Dest = 'Config\examples\wildcard-example.csv' }
                @{ Source = 'Config\examples\single-policy-update.csv'; Dest = 'Config\examples\single-policy-update.csv' }
            )
        }
        
        if (-not $SkipContent) {
            $filesToCopy += @(
                @{ Source = 'Content\README.md'; Dest = 'Content\README.md' }
                @{ Source = 'Content\PolicyTips\warning-tip.html'; Dest = 'Content\PolicyTips\warning-tip.html' }
                @{ Source = 'Content\PolicyTips\simulation-tip.html'; Dest = 'Content\PolicyTips\simulation-tip.html' }
                @{ Source = 'Content\PolicyTips\block-tip.html'; Dest = 'Content\PolicyTips\block-tip.html' }
                @{ Source = 'Content\EmailBodies\standard-notification.html'; Dest = 'Content\EmailBodies\standard-notification.html' }
                @{ Source = 'Content\EmailBodies\manager-notification.html'; Dest = 'Content\EmailBodies\manager-notification.html' }
                @{ Source = 'Content\EmailBodies\executive-notification.html'; Dest = 'Content\EmailBodies\executive-notification.html' }
            )
        }
        
        foreach ($file in $filesToCopy) {
            $sourcePath = Join-Path $templatesPath $file.Source
            $destPath = Join-Path $targetPath $file.Dest
            
            if (-not (Test-Path $sourcePath)) {
                Write-ColorOutput " ⚠️ Template not found: $($file.Source)" -Type Warning
                continue
            }
            
            if ((Test-Path $destPath) -and -not $Force) {
                $result.SkippedFiles += $file.Dest
                Write-ColorOutput " - Skipped (exists): $($file.Dest)" -Type Info
            }
            else {
                if ($PSCmdlet.ShouldProcess($destPath, "Copy File")) {
                    Copy-Item -Path $sourcePath -Destination $destPath -Force
                    $result.CopiedFiles += $file.Dest
                    $action = if (Test-Path $destPath) { "Overwrote" } else { "Copied" }
                    Write-ColorOutput " ✓ $action`: $($file.Dest)" -Type Success
                }
            }
        }
        
        # Summary
        Write-Host ""
        Write-ColorOutput "$('═' * 80)" -Type Header
        Write-ColorOutput " Initialization Complete" -Type Header
        Write-ColorOutput "$('═' * 80)`n" -Type Header
        
        Write-ColorOutput "Summary:" -Type Info
        Write-Host " Directories created: $($result.CreatedDirectories.Count)"
        Write-Host " Files copied: $($result.CopiedFiles.Count)"
        if ($result.SkippedFiles.Count -gt 0) {
            Write-Host " Files skipped: $($result.SkippedFiles.Count) (already exist)"
        }
        
        Write-Host ""
        Write-ColorOutput "Next Steps:" -Type Info
        Write-Host " 1. Review and customize files in Config/ directory"
        Write-Host " 2. Edit HTML templates in Content/ directory to match your organization"
        Write-Host " 3. Run: Update-DLPNotification -ConfigFile .\Config\update-config.csv -WhatIf"
        
        if ($result.SkippedFiles.Count -gt 0 -and -not $Force) {
            Write-Host ""
            Write-ColorOutput "Tip: Use -Force to overwrite existing files with fresh templates" -Type Info
        }
        
        Write-Host ""
        
        return [PSCustomObject]$result
    }
    catch {
        Write-ColorOutput "`n✗ Error during initialization: $($_.Exception.Message)" -Type Error
        $result.Success = $false
        $result.Error = $_.Exception.Message
        return [PSCustomObject]$result
    }
}