require "app/api3/parsers/filter"
require 'db/mongo/models/filter'
require_relative "request_handler"

module Devops
  module API3
    module Handler
      class Filter < RequestHandler

        set_parser Devops::API3::Parser::FilterParser

        def available_images provider
          Devops::Model::Filter.available_images(provider)
        end

        def add_images provider
          images = parser.images
          res = Devops::Model::Filter.add_available_images(images, provider)
          DevopsLogger.logger.info "Added new image filters '#{images.join("', '")}' for provider #{provider}"
          res
        end

        def delete_images provider
          res = Devops::Model::Filter.delete_available_images(parser.images, provider)
          DevopsLogger.logger.info "Removed image filters '#{res.join("', '")}' from provider #{provider}"
          res
        end

      end
    end
  end
end

