1/**
2 * Copyright 2016 IBM Corp.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *    http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/**
18 * AUTOMATICALLY GENERATED CODE - DO NOT MODIFY
19 */
20
21package services
22
23import (
24	"fmt"
25	"strings"
26
27	"github.com/softlayer/softlayer-go/datatypes"
28	"github.com/softlayer/softlayer-go/session"
29	"github.com/softlayer/softlayer-go/sl"
30)
31
32// no documentation yet
33type Search struct {
34	Session *session.Session
35	Options sl.Options
36}
37
38// GetSearchService returns an instance of the Search SoftLayer service
39func GetSearchService(sess *session.Session) Search {
40	return Search{Session: sess}
41}
42
43func (r Search) Id(id int) Search {
44	r.Options.Id = &id
45	return r
46}
47
48func (r Search) Mask(mask string) Search {
49	if !strings.HasPrefix(mask, "mask[") && (strings.Contains(mask, "[") || strings.Contains(mask, ",")) {
50		mask = fmt.Sprintf("mask[%s]", mask)
51	}
52
53	r.Options.Mask = mask
54	return r
55}
56
57func (r Search) Filter(filter string) Search {
58	r.Options.Filter = filter
59	return r
60}
61
62func (r Search) Limit(limit int) Search {
63	r.Options.Limit = &limit
64	return r
65}
66
67func (r Search) Offset(offset int) Search {
68	r.Options.Offset = &offset
69	return r
70}
71
72// This method allows for searching for SoftLayer resources by simple terms and operators.  Fields that are used for searching will be available at sldn.softlayer.com. It returns a collection or array of <b>[[SoftLayer_Container_Search_Result (type)|SoftLayer_Container_Search_Result]]</b> objects that have search metadata for each result and the resulting resource found.
73//
74// The advancedSearch() method recognizes the special <b><code>_objectType:</code></b> quantifier in search strings.  See the documentation for the <b>[[SoftLayer_Search/search|search()]]</b> method on how to restrict searches using object types.
75//
76// The advancedSearch() method recognizes <b>[[SoftLayer_Container_Search_ObjectType_Property (type)|object properties]]</b>, which can also be used to limit searches.  Example:
77//
78// <code>_objectType:Type_1 propertyA:</code><i><code>value</code></i>
79//
80// A search string can specify multiple properties, separated with spaces. Example:
81//
82// <code>_objectType:Type_1 propertyA:</code><i><code>value</code></i> <code>propertyB:</code><i><code>value</code></i>
83//
84// A collection of available object types and their properties can be retrieved by calling the <b>[[SoftLayer_Search/getObjectTypes|getObjectTypes()]]</b> method.
85func (r Search) AdvancedSearch(searchString *string) (resp []datatypes.Container_Search_Result, err error) {
86	params := []interface{}{
87		searchString,
88	}
89	err = r.Session.DoRequest("SoftLayer_Search", "advancedSearch", params, &r.Options, &resp)
90	return
91}
92
93// This method returns a collection of <b>[[SoftLayer_Container_Search_ObjectType (type)|SoftLayer_Container_Search_ObjectType]]</b> containers that specify which indexed object types and properties are exposed for the current user.  These object types can be used to discover searchable data and to create or validate object index search strings.
94//
95// <p> Refer to the <b>[[SoftLayer_Search/search|search()]]</b> and <b>[[SoftLayer_Search/advancedSearch|advancedSearch()]]</b> methods for information on using object types and properties in search strings.
96func (r Search) GetObjectTypes() (resp []datatypes.Container_Search_ObjectType, err error) {
97	err = r.Session.DoRequest("SoftLayer_Search", "getObjectTypes", nil, &r.Options, &resp)
98	return
99}
100
101// This method allows for searching for SoftLayer resources by simple phrase. It returns a collection or array of <b>[[SoftLayer_Container_Search_Result (type)|SoftLayer_Container_Search_Result]]</b> objects that have search metadata for each result and the resulting resource found.
102//
103// This method recognizes the special <b><code>_objectType:</code></b> quantifier in search strings.  This quantifier can be used to restrict a search to specific object types.  Example usage:
104//
105// <code>_objectType:Type_1 </code><i><code>(other search terms...)</code></i>
106//
107// A search string can specify multiple object types, separated by commas (no spaces are permitted between the type names).  Example:
108//
109// <code>_objectType:Type_1,Type_2,Type_3 </code><i><code>(other search terms...)</code></i>
110//
111// If the list of object types is prefixed with a hyphen or minus sign (-), then the specified types are excluded from the search.  Example:
112//
113// <code>_objectType:-Type_4,Type_5 </code><i><code>(other search terms...)</code></i>
114//
115// A collection of available object types can be retrieved by calling the <b>[[SoftLayer_Search/getObjectTypes|getObjectTypes()]]</b> method.
116func (r Search) Search(searchString *string) (resp []datatypes.Container_Search_Result, err error) {
117	params := []interface{}{
118		searchString,
119	}
120	err = r.Session.DoRequest("SoftLayer_Search", "search", params, &r.Options, &resp)
121	return
122}
123