package co.kuznetsov.tomcat.sessions.dynamodb;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMarshalling;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBVersionAttribute;

@DynamoDBTable(tableName = CorpSessionManager.DEFAULT_TABLE_NAME)
public class DynamoSession {
    public static final String SESSION_ID_ATTRIBUTE_NAME = "session_id";
    public static final String EXTENSION_ATTRIBUTE_NAME  = "extension";
    public static final String VERSION_ATTRIBUTE_NAME    = "version";
    public static final String ATTRIBUTES_ATTRIBUTE_NAME = "attributes";

    private String sessionId;
    private DynamoSessionExtension extension;
    private byte[] attributes;
    private Long   version;

    public DynamoSession(String id) {
        this();
        this.sessionId  = id;
    }

    public DynamoSession() {
        this.extension  = new DynamoSessionExtension();
    }

    @DynamoDBHashKey(attributeName = SESSION_ID_ATTRIBUTE_NAME)
    public String getSessionId() {
        return sessionId;
    }

    @DynamoDBAttribute(attributeName = EXTENSION_ATTRIBUTE_NAME)
    @DynamoDBMarshalling(marshallerClass = SessionExtensionMarshaller.class)
    public DynamoSessionExtension getExtension() {
        return extension;
    }

    @DynamoDBVersionAttribute(attributeName = VERSION_ATTRIBUTE_NAME)
    public Long getVersion() {
        return version;
    }

    @DynamoDBAttribute(attributeName = ATTRIBUTES_ATTRIBUTE_NAME)
    public byte[] getAttributes() {
        return attributes;
    }

    public void setExtension(DynamoSessionExtension sessionProps) {
        this.extension = sessionProps;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public void setAttributes(byte[] attributes) {
        this.attributes = attributes;
    }

    public void setVersion(Long version) {
        this.version = version;
    }
}
