require "devops-client/handler/handler"
require "devops-client/options/filter_options"
require "json"
require "devops-client/output/filters"

class Filter < Handler

  output_with Output::Filters

  def initialize(host, def_options)
    @host, @options = host, def_options
    @options_parser = FilterOptions.new(ARGV, def_options)
  end


  def handle
    @command, @options, @args = @options_parser.parse_options_for!
    extract_parameters
    case @command
    when :image_list
        @list = get("/filter/#{@provider}/images")
        output
    when :image_add
        @list = post_body("/filter/#{@provider}/images/add", @image.to_json)
        @list = @list["images"] unless @list.nil?
        output
    when :image_delete
        if question(I18n.t("handler.filter.question.delete", :name => @image.join("', '")))
          @list = post_body("/filter/#{@provider}/images/delete", @image.to_json)
          @list = @list["images"] unless @list.nil?
          output
        end
    end
  end

end
