OctopusMachines.psm1

Import-Module PowershellOctopusClientPS
(Get-Module -ListAvailable PowershellOctopusClientPS).ModuleBase

try
{
    $octoclientpath = Join-Path -Path (Get-Module -ListAvailable PowershellOctopusClientPS).ModuleBase -ChildPath "lib\Octopus.Client.dll"
    $newtonsoftPath = Join-Path -Path (Get-Module -ListAvailable PowershellOctopusClientPS).ModuleBase -ChildPath "lib\Newtonsoft.Json.dll"
    Add-Type -Path $newtonsoftPath
    Add-Type -Path $octoclientpath
}
catch [System.Reflection.ReflectionTypeLoadException]
{    #system.attonations always throws
    #Write-Host "Message: $($_.Exception.Message)"
    #Write-Host "StackTrace: $($_.Exception.StackTrace)"
    #Write-Host "LoaderExceptions: $($_.Exception.LoaderExceptions)"
}
<#
    .SYNOPSIS
    return a setup client
#>

function LoadOctopusClientAndDependancies {
[OutputType([Octopus.Client.OctopusClient])]
    Param(
        [parameter(Mandatory=$true)][String] $url,
        [parameter(Mandatory=$true)][String] $apiKey
    )
    
    $client = [Octopus.Client.OctopusClient]::new([Octopus.Client.OctopusServerEndpoint]::new($url, $apiKey))
    $client
}

function CreateCloudRegion {
    Param(
        [parameter(Mandatory=$true)][String] $octopusURL,
        [parameter(Mandatory=$true)][String] $octopusAPIKey,
        [parameter(Mandatory=$true)][String] $Name,
        [parameter(Mandatory=$true)][String] $Space,
        [parameter(Mandatory=$true)][String] $Enviroment
    )
    <#
    $newWorkerPool = [Octopus.Client.Model.WorkerPoolResource]::new()
        if($createWorkerPool -eq $true){
            $newWorkerPool.Name = $enviromentName
            $newWorkerPool.IsDefault = $false
            $newWorkerPool.Description = "$enviromentName enviroment worker pool"
            $newWorkerPool = $repositoryForSpace.WorkerPools.Create($newWorkerPool)
            write-output "Added worker pool $enviromentName to space $currSpace with id $($newWorkerPool.Id)"
        }

        if($createCloudRegion -eq $true) {
            
        }
    #>

}

function CreateWorkerPool {
    Param(
        [parameter(Mandatory=$true)][String] $octopusURL,
        [parameter(Mandatory=$true)][String] $octopusAPIKey,
        [parameter(Mandatory=$true)][String] $Name,
        [parameter(Mandatory=$true)][String] $Space,
        [parameter(Mandatory=$true)][String] $Enviroment
    )
}