/* 
  AUTOGENERATED FILE
  Run "npm run generateARMClients" to regenerate
  Edting this file directly should be done with extreme caution as not to diverge from ARM REST specs

  Generated from: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/synapse/resource-manager/Microsoft.Synapse/stable/2021-03-01/workspace.json
*/

import { configContext } from "../../../../ConfigContext";
import { armRequest } from "../../request";
import * as Types from "./types";
const apiVersion = "2021-03-01";

/* Returns a list of workspaces in a resource group */
export async function listByResourceGroup(
  subscriptionId: string,
  resourceGroupName: string,
): Promise<Types.WorkspaceInfoListResult> {
  const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Synapse/workspaces`;
  return armRequest({ host: configContext.ARM_ENDPOINT, path, method: "GET", apiVersion });
}

/* Gets a workspace */
export async function get(
  subscriptionId: string,
  resourceGroupName: string,
  workspaceName: string,
): Promise<Types.Workspace> {
  const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Synapse/workspaces/${workspaceName}`;
  return armRequest({ host: configContext.ARM_ENDPOINT, path, method: "GET", apiVersion });
}

/* Updates a workspace */
export async function update(
  subscriptionId: string,
  resourceGroupName: string,
  workspaceName: string,
  body: Types.WorkspacePatchInfo,
): Promise<Types.Workspace> {
  const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Synapse/workspaces/${workspaceName}`;
  return armRequest({ host: configContext.ARM_ENDPOINT, path, method: "PATCH", apiVersion, body });
}

/* Creates or updates a workspace */
export async function createOrUpdate(
  subscriptionId: string,
  resourceGroupName: string,
  workspaceName: string,
  body: Types.Workspace,
): Promise<Types.Workspace> {
  const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Synapse/workspaces/${workspaceName}`;
  return armRequest({ host: configContext.ARM_ENDPOINT, path, method: "PUT", apiVersion, body });
}

/* Deletes a workspace */
export async function destroy(subscriptionId: string, resourceGroupName: string, workspaceName: string): Promise<void> {
  const path = `/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Synapse/workspaces/${workspaceName}`;
  return armRequest({ host: configContext.ARM_ENDPOINT, path, method: "DELETE", apiVersion });
}

/* Returns a list of workspaces in a subscription */
export async function list(subscriptionId: string): Promise<Types.WorkspaceInfoListResult> {
  const path = `/subscriptions/${subscriptionId}/providers/Microsoft.Synapse/workspaces`;
  return armRequest({ host: configContext.ARM_ENDPOINT, path, method: "GET", apiVersion });
}
