func (d *TableDesign) GetItemCount() int64 {
	return d.itemCount
}
GetItemCount returns items count on this table.
package dynamodb
import (
	"fmt"
	SDK "github.com/aws/aws-sdk-go/service/dynamodb"
	"github.com/evalphobia/aws-sdk-go-wrapper/private/pointers"
)
const (
	tableStatusActive = "ACTIVE"
)
type TableDesign struct {
	name          string
	readCapacity  int64
	writeCapacity int64
	HashKey       *SDK.KeySchemaElement
	RangeKey      *SDK.KeySchemaElement
	LSI           []*SDK.LocalSecondaryIndex
	GSI           []*SDK.GlobalSecondaryIndex
	Attributes    map[string]*SDK.AttributeDefinition
	itemCount              int64
	status                 string
	numberOfDecreasesToday int64
}
func NewTableDesignWithHashKeyS(tableName, keyName string) *TableDesign {
	d := newTableDesignWithHashKey(tableName, keyName)
	d.Attributes[keyName] = NewStringAttribute(keyName).ToSDKType()
	return d
}
func NewTableDesignWithHashKeyN(tableName, keyName string) *TableDesign {
	d := newTableDesignWithHashKey(tableName, keyName)
	d.Attributes[keyName] = NewNumberAttribute(keyName).ToSDKType()
	return d
}
func newTableDesignWithHashKey(tableName, hashkeyName string) *TableDesign {
	return &TableDesign{
		name:          tableName,
		HashKey:       NewHashKeyElement(hashkeyName),
		Attributes:    make(map[string]*SDK.AttributeDefinition),
		readCapacity:  1,
		writeCapacity: 1,
	}
}
func newTableDesignFromDescription(desc TableDescription) *TableDesign {
	if desc.IsEmpty() {
		return nil
	}
	d := &TableDesign{
		name:                   desc.TableName,
		status:                 desc.TableStatus,
		itemCount:              desc.ItemCount,
		readCapacity:           desc.ProvisionedThroughput.ReadCapacityUnits,
		writeCapacity:          desc.ProvisionedThroughput.WriteCapacityUnits,
		numberOfDecreasesToday: desc.ProvisionedThroughput.NumberOfDecreasesToday,
		Attributes:             make(map[string]*SDK.AttributeDefinition),
	}
	for _, attr := range desc.AttributeDefinitions {
		d.Attributes[attr.Name] = attr.ToSDKType()
	}
	for _, schema := range desc.KeySchema {
		switch schema.KeyType {
		case "HASH":
			d.HashKey = schema.ToSDKType()
		case "RANGE":
			d.RangeKey = schema.ToSDKType()
		}
	}
	for _, lsi := range desc.LocalSecondaryIndexes {
		d.LSI = append(d.LSI, lsi.ToLSI())
	}
	for _, gsi := range desc.GlobalSecondaryIndexes {
		d.GSI = append(d.GSI, gsi.ToGSI())
	}
	return d
}
func (d *TableDesign) AddRangeKeyS(keyName string) {
	d.RangeKey = NewRangeKeyElement(keyName)
	d.Attributes[keyName] = NewStringAttribute(keyName).ToSDKType()
}
func (d *TableDesign) AddRangeKeyN(keyName string) {
	d.RangeKey = NewRangeKeyElement(keyName)
	d.Attributes[keyName] = NewNumberAttribute(keyName).ToSDKType()
}
func (d *TableDesign) HasRangeKey() bool {
	return d.RangeKey != nil
}
func (d *TableDesign) HasLSI() bool {
	return len(d.LSI) != 0
}
func (d *TableDesign) HasGSI() bool {
	return len(d.GSI) != 0
}
func (d *TableDesign) ListLSI() []*SDK.LocalSecondaryIndex {
	return d.LSI
}
func (d *TableDesign) ListGSI() []*SDK.GlobalSecondaryIndex {
	return d.GSI
}
func (d *TableDesign) AddLSIS(name, keyName string) {
	d.Attributes[keyName] = NewStringAttribute(keyName).ToSDKType()
	schema := NewKeySchema(d.HashKey, NewRangeKeyElement(keyName))
	lsi := NewLSI(name, schema)
	d.LSI = append(d.LSI, lsi)
}
func (d *TableDesign) AddLSIN(name, keyName string) {
	d.Attributes[keyName] = NewNumberAttribute(keyName).ToSDKType()
	schema := NewKeySchema(d.HashKey, NewRangeKeyElement(keyName))
	lsi := NewLSI(name, schema)
	d.LSI = append(d.LSI, lsi)
}
func (d *TableDesign) addGSI(name string, key ...string) error {
	var schema []*SDK.KeySchemaElement
	switch len(key) {
	case 1:
		schema = NewKeySchema(NewHashKeyElement(key[0]))
	case 2:
		schema = NewKeySchema(NewHashKeyElement(key[0]), NewRangeKeyElement(key[1]))
	default:
		return fmt.Errorf("keys must have 1 or 2; name=%s; length=%d;", name, len(key))
	}
	tp := newProvisionedThroughput(d.readCapacity, d.writeCapacity)
	gsi := NewGSI(name, schema, tp)
	d.GSI = append(d.GSI, gsi)
	return nil
}
func (d *TableDesign) AddGSIS(name, hashKey string) error {
	d.Attributes[hashKey] = NewStringAttribute(hashKey).ToSDKType()
	return d.addGSI(name, hashKey)
}
func (d *TableDesign) AddGSIN(name, hashKey string) error {
	d.Attributes[hashKey] = NewNumberAttribute(hashKey).ToSDKType()
	return d.addGSI(name, hashKey)
}
func (d *TableDesign) AddGSISS(name, hashKey, rangeKey string) error {
	d.Attributes[hashKey] = NewStringAttribute(hashKey).ToSDKType()
	d.Attributes[rangeKey] = NewStringAttribute(rangeKey).ToSDKType()
	return d.addGSI(name, hashKey, rangeKey)
}
func (d *TableDesign) AddGSISN(name, hashKey, rangeKey string) error {
	d.Attributes[hashKey] = NewStringAttribute(hashKey).ToSDKType()
	d.Attributes[rangeKey] = NewNumberAttribute(rangeKey).ToSDKType()
	return d.addGSI(name, hashKey, rangeKey)
}
func (d *TableDesign) AddGSINN(name, hashKey, rangeKey string) error {
	d.Attributes[hashKey] = NewNumberAttribute(hashKey).ToSDKType()
	d.Attributes[rangeKey] = NewNumberAttribute(rangeKey).ToSDKType()
	return d.addGSI(name, hashKey, rangeKey)
}
func (d *TableDesign) AddGSINS(name, hashKey, rangeKey string) error {
	d.Attributes[hashKey] = NewNumberAttribute(hashKey).ToSDKType()
	d.Attributes[rangeKey] = NewStringAttribute(rangeKey).ToSDKType()
	return d.addGSI(name, hashKey, rangeKey)
}
func (d *TableDesign) AttributeList() []*SDK.AttributeDefinition {
	var attrs []*SDK.AttributeDefinition
	for _, v := range d.Attributes {
		attrs = append(attrs, v)
	}
	return attrs
}
func (d *TableDesign) GetKeyAttributes() map[string]string {
	m := make(map[string]string)
	for _, attr := range d.Attributes {
		m[*attr.AttributeName] = *attr.AttributeType
	}
	return m
}
func (d *TableDesign) SetThroughput(r, w int64) {
	d.readCapacity = r
	d.writeCapacity = w
}
func (d *TableDesign) GetReadCapacity() int64 {
	return d.readCapacity
}
func (d *TableDesign) GetWriteCapacity() int64 {
	return d.writeCapacity
}
func (d *TableDesign) GetNumberOfDecreasesToday() int64 {
	return d.numberOfDecreasesToday
}
func (d *TableDesign) CreateTableInput() *SDK.CreateTableInput {
	var keys []*SDK.KeySchemaElement
	keys = append(keys, d.HashKey)
	if d.HasRangeKey() {
		keys = append(keys, d.RangeKey)
	}
	in := &SDK.CreateTableInput{
		TableName:             pointers.String(d.name),
		KeySchema:             keys,
		AttributeDefinitions:  d.AttributeList(),
		ProvisionedThroughput: newProvisionedThroughput(d.readCapacity, d.writeCapacity),
	}
	if d.HasLSI() {
		in.LocalSecondaryIndexes = d.ListLSI()
	}
	if d.HasGSI() {
		in.GlobalSecondaryIndexes = d.ListGSI()
	}
	return in
}
func (d *TableDesign) keyAttributeValue(hashValue interface{}, rangeValue ...interface{}) map[string]*SDK.AttributeValue {
	key := make(map[string]*SDK.AttributeValue)
	key[d.GetHashKeyName()] = createAttributeValue(hashValue)
	rangeKey := d.GetRangeKeyName()
	if len(rangeValue) == 1 && rangeKey != "" {
		key[rangeKey] = createAttributeValue(rangeValue[0])
	}
	return key
}
func (d *TableDesign) GetName() string {
	return d.name
}
func (d *TableDesign) GetStatus() string {
	return d.status
}
func (d *TableDesign) IsActive() bool {
	return d.status == tableStatusActive
}