require "devops-client/options/common_options"

class StackOptions < CommonOptions

  commands :create, :delete, :list, :show, :sync, :deploy, :reserve, :unreserve, :change_stack_template

  COMMAND_NAME = "stack"

  def initialize args, def_options
    super(args, def_options)
    self.header = I18n.t("headers.stack")
    self.list_params = ["[provider]"]
    self.show_params = ["STACK"]
    self.create_params = %w(PROJECT ENVIRONMENT CATEGORY)
    self.delete_params = ["STACK"]
    self.sync_params = ["STACK"]
    self.deploy_params = ["STACK"]
    self.reserve_params = ["STACK"]
    self.change_stack_template_params = %w(STACK STACK_TEMPLATE)
  end

  def create_options
    self.options do |parser, options|
      parser.banner << self.create_banner
      parser.resource_name = :stack

      parser.recognize_option_value(:id)
      parser.recognize_option_value(:parameters_file)
      parser.recognize_option_value(:tags_file)
      parser.recognize_option_value(:run_list)
      parser.recognize_option_value(:without_bootstrap, type: :switch, switch_value: true)
      parser.recognize_option_value(:skip_rollback, type: :switch, switch_value: true)
    end
  end

  # QUESTION:
  # Should we check options logic here, or in Handler, or in separate class?

  extend_options_method :list_options do |options|
    if args[2] == "provider" and args[3]
      options[:given_provider] = args[3]
    elsif args[2]
      options[:given_provider] = args[2]
    end
  end

end
