/*
 * Copyright (c) 2012-2015 The original author or authors
 * ------------------------------------------------------
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution.
 *
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * The Apache License v2.0 is available at
 * http://www.opensource.org/licenses/apache2.0.php
 *
 * You may elect to redistribute this code under either of these licenses.
 */
package io.moquette.spi.impl.subscriptions;

import java.io.Serializable;
import io.moquette.parser.proto.messages.AbstractMessage.QOSType;
import io.moquette.spi.ISessionsStore.ClientTopicCouple;

/**
 * Maintain the information about which Topic a certain ClientID is subscribed 
 * and at which QoS
 * 
 * 
 * @author andrea
 */
public class Subscription implements Serializable {
    
    QOSType requestedQos; //max QoS acceptable
    String clientId;
    String topicFilter;
    boolean active = true;
    
    public Subscription(String clientId, String topicFilter, QOSType requestedQos) {
        this.requestedQos = requestedQos;
        this.clientId = clientId;
        this.topicFilter = topicFilter;
    }

    public Subscription(Subscription orig) {
        this.requestedQos = orig.requestedQos;
        this.clientId = orig.clientId;
        this.topicFilter = orig.topicFilter;
        this.active = orig.active;
    }

    public String getClientId() {
        return clientId;
    }

    public QOSType getRequestedQos() {
        return requestedQos;
    }

    public String getTopicFilter() {
        return topicFilter;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Subscription that = (Subscription) o;

        if (clientId != null ? !clientId.equals(that.clientId) : that.clientId != null) return false;
        return !(topicFilter != null ? !topicFilter.equals(that.topicFilter) : that.topicFilter != null);

    }

    @Override
    public int hashCode() {
        int result = clientId != null ? clientId.hashCode() : 0;
        result = 31 * result + (topicFilter != null ? topicFilter.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return String.format("[filter:%s, cliID: %s, qos: %s, active: %s]", this.topicFilter, this.clientId, this.requestedQos, this.active);
    }

    @Override
    public Subscription clone() {
        try {
            return (Subscription) super.clone();
        } catch (CloneNotSupportedException e) {
            return null;
        }
    }

    public ClientTopicCouple asClientTopicCouple() {
        return new ClientTopicCouple(this.clientId, this.topicFilter);
    }
}

@@ -930,16 +930,22 @@
 %0Apublic 
+final 
 class Su
@@ -990,16 +990,22 @@
    %0A    
+final 
 QOSType 
@@ -1039,24 +1039,30 @@
 eptable%0A    
+final 
 String clien
@@ -1070,16 +1070,22 @@
 Id;%0A    
+final 
 String t
@@ -1100,16 +1100,22 @@
 er;%0A    
+final 
 boolean 
@@ -1124,15 +1124,8 @@
 tive
- = true
 ;%0A  
@@ -1320,32 +1320,60 @@
  = topicFilter;%0A
+        this.active = true;%0A
     %7D%0A%0A    publi

Make Subscription class immutable.