1// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17package talent
18
19import (
20	"context"
21	"fmt"
22	"math"
23	"net/url"
24	"time"
25
26	"cloud.google.com/go/longrunning"
27	lroauto "cloud.google.com/go/longrunning/autogen"
28	"github.com/golang/protobuf/proto"
29	gax "github.com/googleapis/gax-go/v2"
30	"google.golang.org/api/iterator"
31	"google.golang.org/api/option"
32	"google.golang.org/api/option/internaloption"
33	gtransport "google.golang.org/api/transport/grpc"
34	talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
35	longrunningpb "google.golang.org/genproto/googleapis/longrunning"
36	"google.golang.org/grpc"
37	"google.golang.org/grpc/codes"
38	"google.golang.org/grpc/metadata"
39)
40
41var newJobClientHook clientHook
42
43// JobCallOptions contains the retry settings for each method of JobClient.
44type JobCallOptions struct {
45	CreateJob          []gax.CallOption
46	BatchCreateJobs    []gax.CallOption
47	GetJob             []gax.CallOption
48	UpdateJob          []gax.CallOption
49	BatchUpdateJobs    []gax.CallOption
50	DeleteJob          []gax.CallOption
51	BatchDeleteJobs    []gax.CallOption
52	ListJobs           []gax.CallOption
53	SearchJobs         []gax.CallOption
54	SearchJobsForAlert []gax.CallOption
55}
56
57func defaultJobClientOptions() []option.ClientOption {
58	return []option.ClientOption{
59		internaloption.WithDefaultEndpoint("jobs.googleapis.com:443"),
60		internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"),
61		internaloption.WithDefaultAudience("https://jobs.googleapis.com/"),
62		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
63		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
64		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
65			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
66	}
67}
68
69func defaultJobCallOptions() *JobCallOptions {
70	return &JobCallOptions{
71		CreateJob:       []gax.CallOption{},
72		BatchCreateJobs: []gax.CallOption{},
73		GetJob: []gax.CallOption{
74			gax.WithRetry(func() gax.Retryer {
75				return gax.OnCodes([]codes.Code{
76					codes.DeadlineExceeded,
77					codes.Unavailable,
78				}, gax.Backoff{
79					Initial:    100 * time.Millisecond,
80					Max:        60000 * time.Millisecond,
81					Multiplier: 1.30,
82				})
83			}),
84		},
85		UpdateJob:       []gax.CallOption{},
86		BatchUpdateJobs: []gax.CallOption{},
87		DeleteJob: []gax.CallOption{
88			gax.WithRetry(func() gax.Retryer {
89				return gax.OnCodes([]codes.Code{
90					codes.DeadlineExceeded,
91					codes.Unavailable,
92				}, gax.Backoff{
93					Initial:    100 * time.Millisecond,
94					Max:        60000 * time.Millisecond,
95					Multiplier: 1.30,
96				})
97			}),
98		},
99		BatchDeleteJobs: []gax.CallOption{},
100		ListJobs: []gax.CallOption{
101			gax.WithRetry(func() gax.Retryer {
102				return gax.OnCodes([]codes.Code{
103					codes.DeadlineExceeded,
104					codes.Unavailable,
105				}, gax.Backoff{
106					Initial:    100 * time.Millisecond,
107					Max:        60000 * time.Millisecond,
108					Multiplier: 1.30,
109				})
110			}),
111		},
112		SearchJobs:         []gax.CallOption{},
113		SearchJobsForAlert: []gax.CallOption{},
114	}
115}
116
117// JobClient is a client for interacting with Cloud Talent Solution API.
118//
119// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
120type JobClient struct {
121	// Connection pool of gRPC connections to the service.
122	connPool gtransport.ConnPool
123
124	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
125	disableDeadlines bool
126
127	// The gRPC API client.
128	jobClient talentpb.JobServiceClient
129
130	// LROClient is used internally to handle longrunning operations.
131	// It is exposed so that its CallOptions can be modified if required.
132	// Users should not Close this client.
133	LROClient *lroauto.OperationsClient
134
135	// The call options for this service.
136	CallOptions *JobCallOptions
137
138	// The x-goog-* metadata to be sent with each request.
139	xGoogMetadata metadata.MD
140}
141
142// NewJobClient creates a new job service client.
143//
144// A service handles job management, including job CRUD, enumeration and search.
145func NewJobClient(ctx context.Context, opts ...option.ClientOption) (*JobClient, error) {
146	clientOpts := defaultJobClientOptions()
147
148	if newJobClientHook != nil {
149		hookOpts, err := newJobClientHook(ctx, clientHookParams{})
150		if err != nil {
151			return nil, err
152		}
153		clientOpts = append(clientOpts, hookOpts...)
154	}
155
156	disableDeadlines, err := checkDisableDeadlines()
157	if err != nil {
158		return nil, err
159	}
160
161	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
162	if err != nil {
163		return nil, err
164	}
165	c := &JobClient{
166		connPool:         connPool,
167		disableDeadlines: disableDeadlines,
168		CallOptions:      defaultJobCallOptions(),
169
170		jobClient: talentpb.NewJobServiceClient(connPool),
171	}
172	c.setGoogleClientInfo()
173
174	c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
175	if err != nil {
176		// This error "should not happen", since we are just reusing old connection pool
177		// and never actually need to dial.
178		// If this does happen, we could leak connp. However, we cannot close conn:
179		// If the user invoked the constructor with option.WithGRPCConn,
180		// we would close a connection that's still in use.
181		// TODO: investigate error conditions.
182		return nil, err
183	}
184	return c, nil
185}
186
187// Connection returns a connection to the API service.
188//
189// Deprecated.
190func (c *JobClient) Connection() *grpc.ClientConn {
191	return c.connPool.Conn()
192}
193
194// Close closes the connection to the API service. The user should invoke this when
195// the client is no longer required.
196func (c *JobClient) Close() error {
197	return c.connPool.Close()
198}
199
200// setGoogleClientInfo sets the name and version of the application in
201// the `x-goog-api-client` header passed on each request. Intended for
202// use by Google-written clients.
203func (c *JobClient) setGoogleClientInfo(keyval ...string) {
204	kv := append([]string{"gl-go", versionGo()}, keyval...)
205	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
206	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
207}
208
209// CreateJob creates a new job.
210//
211// Typically, the job becomes searchable within 10 seconds, but it may take
212// up to 5 minutes.
213func (c *JobClient) CreateJob(ctx context.Context, req *talentpb.CreateJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
214	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
215		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
216		defer cancel()
217		ctx = cctx
218	}
219	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
220	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
221	opts = append(c.CallOptions.CreateJob[0:len(c.CallOptions.CreateJob):len(c.CallOptions.CreateJob)], opts...)
222	var resp *talentpb.Job
223	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
224		var err error
225		resp, err = c.jobClient.CreateJob(ctx, req, settings.GRPC...)
226		return err
227	}, opts...)
228	if err != nil {
229		return nil, err
230	}
231	return resp, nil
232}
233
234// BatchCreateJobs begins executing a batch create jobs operation.
235func (c *JobClient) BatchCreateJobs(ctx context.Context, req *talentpb.BatchCreateJobsRequest, opts ...gax.CallOption) (*BatchCreateJobsOperation, error) {
236	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
237		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
238		defer cancel()
239		ctx = cctx
240	}
241	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
242	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
243	opts = append(c.CallOptions.BatchCreateJobs[0:len(c.CallOptions.BatchCreateJobs):len(c.CallOptions.BatchCreateJobs)], opts...)
244	var resp *longrunningpb.Operation
245	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
246		var err error
247		resp, err = c.jobClient.BatchCreateJobs(ctx, req, settings.GRPC...)
248		return err
249	}, opts...)
250	if err != nil {
251		return nil, err
252	}
253	return &BatchCreateJobsOperation{
254		lro: longrunning.InternalNewOperation(c.LROClient, resp),
255	}, nil
256}
257
258// GetJob retrieves the specified job, whose status is OPEN or recently EXPIRED
259// within the last 90 days.
260func (c *JobClient) GetJob(ctx context.Context, req *talentpb.GetJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
261	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
262		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
263		defer cancel()
264		ctx = cctx
265	}
266	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
267	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
268	opts = append(c.CallOptions.GetJob[0:len(c.CallOptions.GetJob):len(c.CallOptions.GetJob)], opts...)
269	var resp *talentpb.Job
270	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
271		var err error
272		resp, err = c.jobClient.GetJob(ctx, req, settings.GRPC...)
273		return err
274	}, opts...)
275	if err != nil {
276		return nil, err
277	}
278	return resp, nil
279}
280
281// UpdateJob updates specified job.
282//
283// Typically, updated contents become visible in search results within 10
284// seconds, but it may take up to 5 minutes.
285func (c *JobClient) UpdateJob(ctx context.Context, req *talentpb.UpdateJobRequest, opts ...gax.CallOption) (*talentpb.Job, error) {
286	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
287		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
288		defer cancel()
289		ctx = cctx
290	}
291	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "job.name", url.QueryEscape(req.GetJob().GetName())))
292	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
293	opts = append(c.CallOptions.UpdateJob[0:len(c.CallOptions.UpdateJob):len(c.CallOptions.UpdateJob)], opts...)
294	var resp *talentpb.Job
295	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
296		var err error
297		resp, err = c.jobClient.UpdateJob(ctx, req, settings.GRPC...)
298		return err
299	}, opts...)
300	if err != nil {
301		return nil, err
302	}
303	return resp, nil
304}
305
306// BatchUpdateJobs begins executing a batch update jobs operation.
307func (c *JobClient) BatchUpdateJobs(ctx context.Context, req *talentpb.BatchUpdateJobsRequest, opts ...gax.CallOption) (*BatchUpdateJobsOperation, error) {
308	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
309		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
310		defer cancel()
311		ctx = cctx
312	}
313	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
314	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
315	opts = append(c.CallOptions.BatchUpdateJobs[0:len(c.CallOptions.BatchUpdateJobs):len(c.CallOptions.BatchUpdateJobs)], opts...)
316	var resp *longrunningpb.Operation
317	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
318		var err error
319		resp, err = c.jobClient.BatchUpdateJobs(ctx, req, settings.GRPC...)
320		return err
321	}, opts...)
322	if err != nil {
323		return nil, err
324	}
325	return &BatchUpdateJobsOperation{
326		lro: longrunning.InternalNewOperation(c.LROClient, resp),
327	}, nil
328}
329
330// DeleteJob deletes the specified job.
331//
332// Typically, the job becomes unsearchable within 10 seconds, but it may take
333// up to 5 minutes.
334func (c *JobClient) DeleteJob(ctx context.Context, req *talentpb.DeleteJobRequest, opts ...gax.CallOption) error {
335	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
336		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
337		defer cancel()
338		ctx = cctx
339	}
340	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
341	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
342	opts = append(c.CallOptions.DeleteJob[0:len(c.CallOptions.DeleteJob):len(c.CallOptions.DeleteJob)], opts...)
343	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
344		var err error
345		_, err = c.jobClient.DeleteJob(ctx, req, settings.GRPC...)
346		return err
347	}, opts...)
348	return err
349}
350
351// BatchDeleteJobs deletes a list of Jobs by filter.
352func (c *JobClient) BatchDeleteJobs(ctx context.Context, req *talentpb.BatchDeleteJobsRequest, opts ...gax.CallOption) error {
353	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
354		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
355		defer cancel()
356		ctx = cctx
357	}
358	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
359	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
360	opts = append(c.CallOptions.BatchDeleteJobs[0:len(c.CallOptions.BatchDeleteJobs):len(c.CallOptions.BatchDeleteJobs)], opts...)
361	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
362		var err error
363		_, err = c.jobClient.BatchDeleteJobs(ctx, req, settings.GRPC...)
364		return err
365	}, opts...)
366	return err
367}
368
369// ListJobs lists jobs by filter.
370func (c *JobClient) ListJobs(ctx context.Context, req *talentpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator {
371	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
372	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
373	opts = append(c.CallOptions.ListJobs[0:len(c.CallOptions.ListJobs):len(c.CallOptions.ListJobs)], opts...)
374	it := &JobIterator{}
375	req = proto.Clone(req).(*talentpb.ListJobsRequest)
376	it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Job, string, error) {
377		var resp *talentpb.ListJobsResponse
378		req.PageToken = pageToken
379		if pageSize > math.MaxInt32 {
380			req.PageSize = math.MaxInt32
381		} else {
382			req.PageSize = int32(pageSize)
383		}
384		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
385			var err error
386			resp, err = c.jobClient.ListJobs(ctx, req, settings.GRPC...)
387			return err
388		}, opts...)
389		if err != nil {
390			return nil, "", err
391		}
392
393		it.Response = resp
394		return resp.GetJobs(), resp.GetNextPageToken(), nil
395	}
396	fetch := func(pageSize int, pageToken string) (string, error) {
397		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
398		if err != nil {
399			return "", err
400		}
401		it.items = append(it.items, items...)
402		return nextPageToken, nil
403	}
404	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
405	it.pageInfo.MaxSize = int(req.GetPageSize())
406	it.pageInfo.Token = req.GetPageToken()
407	return it
408}
409
410// SearchJobs searches for jobs using the provided SearchJobsRequest.
411//
412// This call constrains the visibility of jobs
413// present in the database, and only returns jobs that the caller has
414// permission to search against.
415func (c *JobClient) SearchJobs(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) (*talentpb.SearchJobsResponse, error) {
416	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
417		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
418		defer cancel()
419		ctx = cctx
420	}
421	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
422	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
423	opts = append(c.CallOptions.SearchJobs[0:len(c.CallOptions.SearchJobs):len(c.CallOptions.SearchJobs)], opts...)
424	var resp *talentpb.SearchJobsResponse
425	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
426		var err error
427		resp, err = c.jobClient.SearchJobs(ctx, req, settings.GRPC...)
428		return err
429	}, opts...)
430	if err != nil {
431		return nil, err
432	}
433	return resp, nil
434}
435
436// SearchJobsForAlert searches for jobs using the provided SearchJobsRequest.
437//
438// This API call is intended for the use case of targeting passive job
439// seekers (for example, job seekers who have signed up to receive email
440// alerts about potential job opportunities), and has different algorithmic
441// adjustments that are targeted to passive job seekers.
442//
443// This call constrains the visibility of jobs
444// present in the database, and only returns jobs the caller has
445// permission to search against.
446func (c *JobClient) SearchJobsForAlert(ctx context.Context, req *talentpb.SearchJobsRequest, opts ...gax.CallOption) *SearchJobsResponse_MatchingJobIterator {
447	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
448	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
449	opts = append(c.CallOptions.SearchJobsForAlert[0:len(c.CallOptions.SearchJobsForAlert):len(c.CallOptions.SearchJobsForAlert)], opts...)
450	it := &SearchJobsResponse_MatchingJobIterator{}
451	req = proto.Clone(req).(*talentpb.SearchJobsRequest)
452	it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.SearchJobsResponse_MatchingJob, string, error) {
453		var resp *talentpb.SearchJobsResponse
454		req.PageToken = pageToken
455		if pageSize > math.MaxInt32 {
456			req.PageSize = math.MaxInt32
457		} else {
458			req.PageSize = int32(pageSize)
459		}
460		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
461			var err error
462			resp, err = c.jobClient.SearchJobsForAlert(ctx, req, settings.GRPC...)
463			return err
464		}, opts...)
465		if err != nil {
466			return nil, "", err
467		}
468
469		it.Response = resp
470		return resp.GetMatchingJobs(), resp.GetNextPageToken(), nil
471	}
472	fetch := func(pageSize int, pageToken string) (string, error) {
473		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
474		if err != nil {
475			return "", err
476		}
477		it.items = append(it.items, items...)
478		return nextPageToken, nil
479	}
480	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
481	it.pageInfo.MaxSize = int(req.GetPageSize())
482	it.pageInfo.Token = req.GetPageToken()
483	return it
484}
485
486// BatchCreateJobsOperation manages a long-running operation from BatchCreateJobs.
487type BatchCreateJobsOperation struct {
488	lro *longrunning.Operation
489}
490
491// BatchCreateJobsOperation returns a new BatchCreateJobsOperation from a given name.
492// The name must be that of a previously created BatchCreateJobsOperation, possibly from a different process.
493func (c *JobClient) BatchCreateJobsOperation(name string) *BatchCreateJobsOperation {
494	return &BatchCreateJobsOperation{
495		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
496	}
497}
498
499// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
500//
501// See documentation of Poll for error-handling information.
502func (op *BatchCreateJobsOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*talentpb.JobOperationResult, error) {
503	var resp talentpb.JobOperationResult
504	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
505		return nil, err
506	}
507	return &resp, nil
508}
509
510// Poll fetches the latest state of the long-running operation.
511//
512// Poll also fetches the latest metadata, which can be retrieved by Metadata.
513//
514// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
515// the operation has completed with failure, the error is returned and op.Done will return true.
516// If Poll succeeds and the operation has completed successfully,
517// op.Done will return true, and the response of the operation is returned.
518// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
519func (op *BatchCreateJobsOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*talentpb.JobOperationResult, error) {
520	var resp talentpb.JobOperationResult
521	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
522		return nil, err
523	}
524	if !op.Done() {
525		return nil, nil
526	}
527	return &resp, nil
528}
529
530// Metadata returns metadata associated with the long-running operation.
531// Metadata itself does not contact the server, but Poll does.
532// To get the latest metadata, call this method after a successful call to Poll.
533// If the metadata is not available, the returned metadata and error are both nil.
534func (op *BatchCreateJobsOperation) Metadata() (*talentpb.BatchOperationMetadata, error) {
535	var meta talentpb.BatchOperationMetadata
536	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
537		return nil, nil
538	} else if err != nil {
539		return nil, err
540	}
541	return &meta, nil
542}
543
544// Done reports whether the long-running operation has completed.
545func (op *BatchCreateJobsOperation) Done() bool {
546	return op.lro.Done()
547}
548
549// Name returns the name of the long-running operation.
550// The name is assigned by the server and is unique within the service from which the operation is created.
551func (op *BatchCreateJobsOperation) Name() string {
552	return op.lro.Name()
553}
554
555// BatchUpdateJobsOperation manages a long-running operation from BatchUpdateJobs.
556type BatchUpdateJobsOperation struct {
557	lro *longrunning.Operation
558}
559
560// BatchUpdateJobsOperation returns a new BatchUpdateJobsOperation from a given name.
561// The name must be that of a previously created BatchUpdateJobsOperation, possibly from a different process.
562func (c *JobClient) BatchUpdateJobsOperation(name string) *BatchUpdateJobsOperation {
563	return &BatchUpdateJobsOperation{
564		lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}),
565	}
566}
567
568// Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
569//
570// See documentation of Poll for error-handling information.
571func (op *BatchUpdateJobsOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*talentpb.JobOperationResult, error) {
572	var resp talentpb.JobOperationResult
573	if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
574		return nil, err
575	}
576	return &resp, nil
577}
578
579// Poll fetches the latest state of the long-running operation.
580//
581// Poll also fetches the latest metadata, which can be retrieved by Metadata.
582//
583// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
584// the operation has completed with failure, the error is returned and op.Done will return true.
585// If Poll succeeds and the operation has completed successfully,
586// op.Done will return true, and the response of the operation is returned.
587// If Poll succeeds and the operation has not completed, the returned response and error are both nil.
588func (op *BatchUpdateJobsOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*talentpb.JobOperationResult, error) {
589	var resp talentpb.JobOperationResult
590	if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
591		return nil, err
592	}
593	if !op.Done() {
594		return nil, nil
595	}
596	return &resp, nil
597}
598
599// Metadata returns metadata associated with the long-running operation.
600// Metadata itself does not contact the server, but Poll does.
601// To get the latest metadata, call this method after a successful call to Poll.
602// If the metadata is not available, the returned metadata and error are both nil.
603func (op *BatchUpdateJobsOperation) Metadata() (*talentpb.BatchOperationMetadata, error) {
604	var meta talentpb.BatchOperationMetadata
605	if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
606		return nil, nil
607	} else if err != nil {
608		return nil, err
609	}
610	return &meta, nil
611}
612
613// Done reports whether the long-running operation has completed.
614func (op *BatchUpdateJobsOperation) Done() bool {
615	return op.lro.Done()
616}
617
618// Name returns the name of the long-running operation.
619// The name is assigned by the server and is unique within the service from which the operation is created.
620func (op *BatchUpdateJobsOperation) Name() string {
621	return op.lro.Name()
622}
623
624// JobIterator manages a stream of *talentpb.Job.
625type JobIterator struct {
626	items    []*talentpb.Job
627	pageInfo *iterator.PageInfo
628	nextFunc func() error
629
630	// Response is the raw response for the current page.
631	// It must be cast to the RPC response type.
632	// Calling Next() or InternalFetch() updates this value.
633	Response interface{}
634
635	// InternalFetch is for use by the Google Cloud Libraries only.
636	// It is not part of the stable interface of this package.
637	//
638	// InternalFetch returns results from a single call to the underlying RPC.
639	// The number of results is no greater than pageSize.
640	// If there are no more results, nextPageToken is empty and err is nil.
641	InternalFetch func(pageSize int, pageToken string) (results []*talentpb.Job, nextPageToken string, err error)
642}
643
644// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
645func (it *JobIterator) PageInfo() *iterator.PageInfo {
646	return it.pageInfo
647}
648
649// Next returns the next result. Its second return value is iterator.Done if there are no more
650// results. Once Next returns Done, all subsequent calls will return Done.
651func (it *JobIterator) Next() (*talentpb.Job, error) {
652	var item *talentpb.Job
653	if err := it.nextFunc(); err != nil {
654		return item, err
655	}
656	item = it.items[0]
657	it.items = it.items[1:]
658	return item, nil
659}
660
661func (it *JobIterator) bufLen() int {
662	return len(it.items)
663}
664
665func (it *JobIterator) takeBuf() interface{} {
666	b := it.items
667	it.items = nil
668	return b
669}
670
671// SearchJobsResponse_MatchingJobIterator manages a stream of *talentpb.SearchJobsResponse_MatchingJob.
672type SearchJobsResponse_MatchingJobIterator struct {
673	items    []*talentpb.SearchJobsResponse_MatchingJob
674	pageInfo *iterator.PageInfo
675	nextFunc func() error
676
677	// Response is the raw response for the current page.
678	// It must be cast to the RPC response type.
679	// Calling Next() or InternalFetch() updates this value.
680	Response interface{}
681
682	// InternalFetch is for use by the Google Cloud Libraries only.
683	// It is not part of the stable interface of this package.
684	//
685	// InternalFetch returns results from a single call to the underlying RPC.
686	// The number of results is no greater than pageSize.
687	// If there are no more results, nextPageToken is empty and err is nil.
688	InternalFetch func(pageSize int, pageToken string) (results []*talentpb.SearchJobsResponse_MatchingJob, nextPageToken string, err error)
689}
690
691// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
692func (it *SearchJobsResponse_MatchingJobIterator) PageInfo() *iterator.PageInfo {
693	return it.pageInfo
694}
695
696// Next returns the next result. Its second return value is iterator.Done if there are no more
697// results. Once Next returns Done, all subsequent calls will return Done.
698func (it *SearchJobsResponse_MatchingJobIterator) Next() (*talentpb.SearchJobsResponse_MatchingJob, error) {
699	var item *talentpb.SearchJobsResponse_MatchingJob
700	if err := it.nextFunc(); err != nil {
701		return item, err
702	}
703	item = it.items[0]
704	it.items = it.items[1:]
705	return item, nil
706}
707
708func (it *SearchJobsResponse_MatchingJobIterator) bufLen() int {
709	return len(it.items)
710}
711
712func (it *SearchJobsResponse_MatchingJobIterator) takeBuf() interface{} {
713	b := it.items
714	it.items = nil
715	return b
716}
717