//
// Copyright 2019 AT&T Intellectual Property
// Copyright 2019 Nokia
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package common
/*
ISdlInstance integrates (wraps) the functionality that sdlgo library provides
 */
type ISdlInstance interface {
	SubscribeChannel(cb func(string, ...string), channels ...string) error
	UnsubscribeChannel(channels ...string) error
	Close() error
	SetAndPublish(channelsAndEvents []string, pairs ...interface{}) error
	Set(pairs ...interface{}) error
	Get(keys []string) (map[string]interface{}, error)
	SetIfAndPublish(channelsAndEvents []string, key string, oldData, newData interface{}) (bool, error)
	SetIf(key string, oldData, newData interface{}) (bool, error)
	SetIfNotExistsAndPublish(channelsAndEvents []string, key string, data interface{}) (bool, error)
	SetIfNotExists(key string, data interface{}) (bool, error)
	RemoveAndPublish(channelsAndEvents []string, keys []string) error
	Remove(keys []string) error
	RemoveIfAndPublish(channelsAndEvents []string, key string, data interface{}) (bool, error)
	RemoveIf(key string, data interface{}) (bool, error)
	GetAll() ([]string, error)
	RemoveAll() error
	RemoveAllAndPublish(channelsAndEvents []string) error
	AddMember(group string, member ...interface{}) error
	RemoveMember(group string, member ...interface{}) error
	RemoveGroup(group string) error
	GetMembers(group string) ([]string, error)
	IsMember(group string, member interface{}) (bool, error)
	GroupSize(group string) (int64, error)
}
