/// <summary>
        /// Initializes a new instance of the <see cref="DeleteResourceTask"/> class.
        /// </summary>
        /// <param name="resourceLog">The resource log to delete.</param>
        public DeleteResourceTask(ResourceLog resourceLog)
        {
            if (resourceLog == null)
            {
                throw new ArgumentNullException(nameof(resourceLog));
            }

            ResourceLog = resourceLog;
        }
        /// <summary>
        /// Deletes a resource by CaaS identifier and waits.
        /// </summary>
        /// <param name="caasId">The CaaS identifier.</param>
        /// <returns>The async <see cref="Task"/>.</returns>
        public async Task<ResourceLog> DeleteAndWait(string caasId)
        {
            var response = new ResourceLog
            {
                CaasId = caasId,
                ResourceId = _resourceId,
                ResourceType = _resourceType,
                DeploymentStatus = ResourceLogStatus.Deleted
            };

            try
            {
                bool wait = await DeleteExistingResource(caasId);
                if (wait)
                {
                    await WaitForDelete(caasId);
                }
            }
            catch (CaasException ex)
            {
                _logProvider.LogError(ex.Message);

                response.DeploymentStatus = ResourceLogStatus.Failed;
                response.Error = new Error
                {
                    Message = ex.Message,
                    Operation = ex.Operation,
                    ResponseCode = ex.ResponseCode
                };
            }

            return response;
        }
        /// <summary>
        /// Deploys the supplied resource and waits.
        /// </summary>
        /// <param name="resourceDefinition">The resource definition.</param>
        /// <returns>The async <see cref="Task"/>.</returns>
        public async Task<ResourceLog> DeployAndWait(JObject resourceDefinition)
        {
            var response = new ResourceLog() { ResourceId = _resourceId, ResourceType = _resourceType };

            try
            {
                if (_resourceApi.ListUrl != null)
                {
                    var ids = GetResourceIdentifiers(resourceDefinition);
                    var existingResourceDetails = (await GetResourceByIdentifiers(ids)).SingleOrDefault();
                    if (existingResourceDetails != null)
                    {
                        if (_resourceApi.EditUrl == null)
                        {
                            _logProvider.LogMessage($"Resource '{_resourceId}' already exists and cannot be updated. Using existing resource even if its definition doesn't match the template.");
                            response.Details = existingResourceDetails;
                            response.CaasId = response.Details["id"].Value<string>();
                            response.DeploymentStatus = ResourceLogStatus.UsedExisting;
                            return response;
                        }
                        else
                        {
                            var existingId = existingResourceDetails["id"].Value<string>();
                            await UpdateExistingResource(existingId, resourceDefinition);
                            response.Details = await Get(existingId);
                            response.CaasId = response.Details["id"].Value<string>();
                            response.DeploymentStatus = ResourceLogStatus.Updated;
                            return response;
                        }
                    }
                }

                var id = await DeployNewResource(resourceDefinition);
                response.Details = await WaitForDeploy(id);
                response.CaasId = response.Details["id"].Value<string>();
                response.DeploymentStatus = ResourceLogStatus.Deployed;
                return response;
            }
            catch (CaasException ex)
            {
                _logProvider.LogError(ex.Message);

                response.DeploymentStatus = ResourceLogStatus.Failed;
                response.Error = new Error
                {
                    Message = ex.Message,
                    Operation = ex.Operation,
                    ResponseCode = ex.ResponseCode
                };

                return response;
            }
        }