import type { WebSiteManagementModels } from '@azure/arm-appservice' ; import { isNullOrUndefined } from 'util' ; import * as vscode from 'vscode' ; import { DialogResponses , IActionContext } from 'vscode-azureextensionui' ; import { ext } from './extensionVariables' ; import { localize } from './localize' ; import { ParsedSite } from './SiteClient' ; export async function deleteSite ( context , site ) { const confirmMessage = site . isSlot ? localize ( 'confirmDeleteSlot' , 'Are you sure you want to delete slot "{0}"?' , site . fullName ) : site . isFunctionApp ? localize ( 'confirmDeleteFunctionApp' , 'Are you sure you want to delete function app "{0}"?' , site . fullName ) : localize ( 'confirmDeleteWebApp' , 'Are you sure you want to delete web app "{0}"?' , site . fullName ) ; await context . ui . showWarningMessage ( confirmMessage , { modal : true , stepName : 'confirmDelete' } , DialogResponses . deleteResponse ) ; let plan ; let deletePlan = false ; const client = await site . createClient ( context ) ; if ( ! site . isSlot ) { plan = await client . getAppServicePlan ( ) ; } if ( ! site . isSlot && plan && ! isNullOrUndefined ( plan . numberOfSites ) && plan . numberOfSites < 2 ) { const message = localize ( 'deleteLastServicePlan' , 'This is the last app in the App Service plan "{0}". Do you want to delete this App Service plan to prevent unexpected charges?' , plan . name ) ; const input = await context . ui . showWarningMessage ( message , { modal : true , stepName : 'lastAppOnPlan' } , DialogResponses . yes , DialogResponses . no ) ; deletePlan = input === DialogResponses . yes ; } const deleting = site . isSlot ? localize ( 'DeletingSlot' , 'Deleting slot "{0}"...' , site . fullName ) : site . isFunctionApp ? localize ( 'DeletingFunctionApp' , 'Deleting function app "{0}"...' , site . fullName ) : localize ( 'DeletingWebApp' , 'Deleting web app "{0}"...' , site . fullName ) ; const deleteSucceeded = site . isSlot ? localize ( 'deletedSlot' , 'Successfully deleted slot "{0}".' , site . fullName ) : site . isFunctionApp ? localize ( 'deletedFunctionApp' , 'Successfully deleted function app "{0}".' , site . fullName ) : localize ( 'deletedWebApp' , 'Successfully deleted web app "{0}".' , site . fullName ) ; await vscode . window . withProgress ( { location : vscode . ProgressLocation . Notification , title : deleting } , async ( ) : Promise < void > => { ext . outputChannel . appendLog ( deleting ) ; await client . deleteMethod ( { deleteEmptyServerFarm : deletePlan } ) ; void vscode . window . showInformationMessage ( deleteSucceeded ) ; ext . outputChannel . appendLog ( deleteSucceeded ) ; } ) ; }