Classes.ps1

class GraphBatch {
    [string]$id 
    [string]$method = "GET"
    [string]$url
    [PSCustomObject]$body
    [HashTable]$headers

    GraphBatch ([string]$url) {
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
        $this.id = $this.url
    }
    GraphBatch ([string]$idOrMethod, [string]$url) {
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
        if ($idOrMethod -in ("Default", "Delete", "Get", "Head", "Merge", "Options", "Patch", "Post", "Put")) { $this.Method = $idOrMethod.ToUpper() } else { $this.id = $idOrMethod }
    }
    GraphBatch ([string]$id, [string]$method, [string]$url) {
        if ($Method -notin ("Default", "Delete", "Get", "Head", "Merge", "Options", "Patch", "Post", "Put")) { Throw "Invalid Method" }
        $this.Method = $method.ToUpper()
        $this.id = $id
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
    }
    GraphBatch ([string]$id, [string]$method, [string]$url, [HashTable]$headers) {
        if ($Method -notin ("Default", "Delete", "Get", "Head", "Merge", "Options", "Patch", "Post", "Put")) { Throw "Invalid Method" }
        $this.Method = $method.ToUpper()
        $this.id = $id
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
        $this.headers = $headers
    }
    GraphBatch ([string]$id, [string]$method, [string]$url, [string]$body, [HashTable]$headers) {
        if ($Method -notin ("Default", "Delete", "Get", "Head", "Merge", "Options", "Patch", "Post", "Put")) { Throw "Invalid Method" }
        $this.Method = $method.ToUpper()
        $this.id = $id
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
        $this.body = $body | ConvertFrom-Json
        $this.headers = $headers
        $this.headers."Content-Type" = "application/json"
    }
    GraphBatch ([string]$id, [string]$method, [string]$url, [PSCustomObject]$body, [HashTable]$headers) {
        if ($Method -notin ("Default", "Delete", "Get", "Head", "Merge", "Options", "Patch", "Post", "Put")) { Throw "Invalid Method" }
        $this.Method = $method.ToUpper()
        $this.id = $id
        $this.url = $url.Replace("https://graph.microsoft.com/v1.0", "").Replace("https://graph.microsoft.com/beta", "").Replace("//", "/")
        $this.body = $body
        $this.headers = $headers
        $this.headers."Content-Type" = "application/json"
    }
}