module Validators
  class DeployEnv::Groups < Base

    def valid?
      return true if @model.groups.nil?
      subnets_filter = @model.subnets_filter
      available_groups = @model.provider_instance.groups(subnets_filter).keys

      @invalid_groups = @model.groups - available_groups
      @invalid_groups.empty?
    end

    def message
      "Invalid groups '#{@invalid_groups.join("', '")}'."
    end
  end
end