--[=[
	Saves all stored data.
	@return Promise
]=]

function DataStore:Save()
	if self:DidLoadFail() then
		warn("[DataStore] - Not saving, failed to load")
		return Promise.rejected("Load not successful, not saving")
	end

	if DEBUG_WRITING then
		print("[DataStore.Save] - Starting save routine")
	end

	-- Avoid constructing promises for every callback down the datastore
	-- upon save.
	return (self:_promiseInvokeSavingCallbacks() or Promise.resolved())
		:Then(function()
			if not self:HasWritableData() then
				-- Nothing to save, don't update anything
				if DEBUG_WRITING then
					print("[DataStore.Save] - Not saving, nothing staged")
				end
				return nil
			else
				return self:_saveData(self:GetNewWriter())
			end
		end)
end
