const _ = require('lodash');

const OPTIONS = {
  UTF8: utf8,
  'UTF-8': utf8
};

module.exports = {
  directive: 'OPTS',
  handler: function ({command} = {}) {
    if (!_.has(command, 'arg')) return this.reply(501);

    const [_option, ...args] = command.arg.split(' ');
    const option = _.toUpper(_option);

    if (!OPTIONS.hasOwnProperty(option)) return this.reply(500);
    return OPTIONS[option].call(this, args);
  },
  syntax: '{{cmd}}',
  description: 'Select options for a feature'
};

function utf8([setting] = []) {
  switch (_.toUpper(setting)) {
    case 'ON':
      this.encoding = 'utf8';
      return this.reply(200, 'UTF8 encoding on');
    case 'OFF':
      this.encoding = 'ascii';
      return this.reply(200, 'UTF8 encoding off');
    default:
      return this.reply(501, 'Unknown setting for option');
  }
}

@@ -524,16 +524,48 @@
 = %5B%5D) %7B%0A
+  const getEncoding = () =%3E %7B%0A  
   switch
@@ -588,24 +588,26 @@
 ing)) %7B%0A    
+  
 case 'ON':%0A 
@@ -608,44 +608,148 @@
 ON':
-%0A      this.encoding = 'utf8';%0A     
+ return 'utf8';%0A      case 'OFF': return 'ascii';%0A      default: return null;%0A    %7D%0A  %7D;%0A%0A  const encoding = getEncoding();%0A  if (!encoding)
  ret
@@ -767,207 +767,210 @@
 ply(
-200
+501
 , 'U
-TF8 encoding on');%0A    case 'OFF':%0A      this.encoding = 'ascii';%0A      return this.reply(200, 'UTF8 encoding off');%0A    default:%0A      return this.reply(501, 'Unknown setting for option');%0A  %7D
+nknown setting for option');%0A%0A  this.encoding = encoding;%0A  if (this.transferType !== 'binary') this.transferType = this.encoding;%0A%0A  return this.reply(200, %60UTF8 encoding $%7B_.toLower(setting)%7D%60);
 %0A%7D%0A

simplify setting