/*
** Module   : TerminalSessionSettings.java
** Abstract : Configuration for a terminal session test.
**
** Copyright (c) 2021, Golden Code Development Corporation.
**
** -#- -I- --Date-- ---------------------------------------Description----------------------------------------
** 001 CA  20210827 Created initial version.
** 002 CA  20210902 The executor must be thread-local.
*/

/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.goldencode.harness;

import com.goldencode.harness.transport.*;

/**
 * Stores configuration to establish a remote terminal session via TCP/IP.
 */
public class TerminalSessionSettings
extends SessionSettings
{
   /** Host to which to connect. */
   public String host = "localhost";
   
   /** Port number for the socket. */
   public int port = 22;
   
   /** Account name. */
   public String userid = null;
   
   /** Account password. */
   public String password = null;
   
   /** Terminal type to emulate. */
   public String termType = "vt320";
   
   /** Number of columns (width) of the terminal. */
   public int termColumns = 80;
   
   /** Number of rows (height) of the terminal. */
   public int termRows = 24;
   
   /** Communication session protocol. */
   public TransportType protocol = TransportType.SSH2;
   
   /**
    * Default constructor.
    */
   public TerminalSessionSettings()
   {
   }
   
   /**
    * Copy constructor.
    *
    * @param    original
    *           Instance from which to copy.
    */
   public TerminalSessionSettings(TerminalSessionSettings original)
   {
      super(original);
      
      this.host        = original.host;
      this.port        = original.port;
      this.userid      = original.userid;
      this.password    = original.password;
      this.termType    = original.termType;
      this.termColumns = original.termColumns;
      this.termRows    = original.termRows;
      this.protocol    = original.protocol;
   }
   
   /**
    * Get text representation of the configurations for this session - each pair represents the configuration
    * name and its value.
    * 
    * @return   See above.
    */
   @Override
   public String[][] getConfigs()
   {
      return new String[][]
      {
         { "Host", host },
         { "Port", Integer.toString(port) },
         { "Userid", userid},
         { "Protocol", protocol.toString() },
         { "Terminal Type", termType },
         { "Terminal Columns", Integer.toString(termColumns) },
         { "Terminal Rows", Integer.toString(termRows) }
      };
   }
   
   /**
    * Duplicate this configuration.
    * 
    * @return   See above.
    */
   @Override
   public SessionSettings duplicate()
   {
      return new TerminalSessionSettings(this);
   }
   
   /**
    * Build a new executor.
    * 
    * @param    rc
    *           Object in which to store the details of non-testing failures.
    *           
    * @return   The {@link #executor}.
    */
   @Override
   protected TestExecutor buildExecutor(FailureNotification rc)
   {
      return new TerminalTestExecutor(this, rc);
   }
}
