/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.messaginghub.amqperative;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Options that control the behaviour of the {@link Session} created from them.
 */
public class SessionOptions {

    static final SessionOptions DEFAULT = new SessionOptions();

    private long sendTimeout = ConnectionOptions.DEFAULT_SEND_TIMEOUT;
    private long requestTimeout = ConnectionOptions.DEFAULT_REQUEST_TIMEOUT;
    private long openTimeout = ConnectionOptions.DEFAULT_OPEN_TIMEOUT;
    private long closeTimeout = ConnectionOptions.DEFAULT_CLOSE_TIMEOUT;

    private String[] offeredCapabilities;
    private String[] desiredCapabilities;
    private Map<String, Object> properties;

    public SessionOptions() {
    }

    public SessionOptions(SessionOptions options) {
        if (options != null) {
            options.copyInto(this);
        }
    }

    /**
     * Copy all options from this {@link SessionOptions} instance into the instance
     * provided.
     *
     * @param other
     *      the target of this copy operation.
     *
     * @return this options class for chaining.
     */
    protected SessionOptions copyInto(SessionOptions other) {
        other.closeTimeout(closeTimeout);
        other.openTimeout(openTimeout);
        other.sendTimeout(sendTimeout);
        other.requestTimeout(requestTimeout);

        if (offeredCapabilities != null) {
            other.offeredCapabilities(Arrays.copyOf(offeredCapabilities, offeredCapabilities.length));
        }
        if (desiredCapabilities != null) {
            other.desiredCapabilities(Arrays.copyOf(desiredCapabilities, desiredCapabilities.length));
        }
        if (properties != null) {
            other.properties(new HashMap<>(properties));
        }

        return this;
    }

    public long closeTimeout() {
        return closeTimeout;
    }

    public void closeTimeout(long closeTimeout) {
        this.closeTimeout = closeTimeout;
    }

    public long openTimeout() {
        return openTimeout;
    }

    public void openTimeout(long connectTimeout) {
        this.openTimeout = connectTimeout;
    }

    public long sendTimeout() {
        return sendTimeout;
    }

    public void sendTimeout(long sendTimeout) {
        this.sendTimeout = sendTimeout;
    }

    public long requestTimeout() {
        return requestTimeout;
    }

    public void requestTimeout(long requestTimeout) {
        this.requestTimeout = requestTimeout;
    }

    /**
     * @return the offeredCapabilities
     */
    public String[] offeredCapabilities() {
        return offeredCapabilities;
    }

    /**
     * @param offeredCapabilities the offeredCapabilities to set
     */
    public void offeredCapabilities(String... offeredCapabilities) {
        this.offeredCapabilities = offeredCapabilities;
    }

    /**
     * @return the desiredCapabilities
     */
    public String[] desiredCapabilities() {
        return desiredCapabilities;
    }

    /**
     * @param desiredCapabilities the desiredCapabilities to set
     */
    public void desiredCapabilities(String... desiredCapabilities) {
        this.desiredCapabilities = desiredCapabilities;
    }

    /**
     * @return the properties
     */
    public Map<String, Object> properties() {
        return properties;
    }

    /**
     * @param properties the properties to set
     */
    public void properties(Map<String, Object> properties) {
        this.properties = properties;
    }
}

@@ -2687,20 +2687,30 @@
  public 
-void
+SessionOptions
  closeTi
@@ -2770,32 +2770,53 @@
 = closeTimeout;%0A
+        return this;%0A
     %7D%0A%0A    publi
@@ -2884,20 +2884,30 @@
  public 
-void
+SessionOptions
  openTim
@@ -2969,32 +2969,53 @@
 connectTimeout;%0A
+        return this;%0A
     %7D%0A%0A    publi
@@ -3083,20 +3083,30 @@
  public 
-void
+SessionOptions
  sendTim
@@ -3162,32 +3162,53 @@
  = sendTimeout;%0A
+        return this;%0A
     %7D%0A%0A    publi
@@ -3282,20 +3282,30 @@
  public 
-void
+SessionOptions
  request
@@ -3373,32 +3373,53 @@
 requestTimeout;%0A
+        return this;%0A
     %7D%0A%0A    /**%0A 
@@ -3630,33 +3630,103 @@
 t%0A     *
-/%0A    public void
+%0A     * @return this %7B@link SessionOptions%7D instance.%0A     */%0A    public SessionOptions
  offered
@@ -3819,32 +3819,53 @@
 edCapabilities;%0A
+        return this;%0A
     %7D%0A%0A    /**%0A 
@@ -4076,33 +4076,103 @@
 t%0A     *
-/%0A    public void
+%0A     * @return this %7B@link SessionOptions%7D instance.%0A     */%0A    public SessionOptions
  desired
@@ -4265,32 +4265,53 @@
 edCapabilities;%0A
+        return this;%0A
     %7D%0A%0A    /**%0A 
@@ -4492,25 +4492,95 @@
    *
-/%0A    public void
+%0A     * @return this %7B@link SessionOptions%7D instance.%0A     */%0A    public SessionOptions
  pro
@@ -4655,20 +4655,41 @@
 properties;%0A
+        return this;%0A
     %7D%0A%7D%0A

Add return of self for options set chaining as other options types do