/// <summary>
 /// Patches this model with fields in the specified resource.
 /// </summary>
 /// <remarks>
 /// This method delegates to <see cref="BigQueryClient.PatchModel(ModelReference, Model, PatchModelOptions)"/>.
 /// </remarks>
 /// <param name="resource">The resource to patch with. Must not be null.</param>
 /// <param name="matchETag">If true, the etag from <see cref="Resource"/> is propagated into <paramref name="resource"/> for
 /// optimistic concurrency. Otherwise, <paramref name="resource"/> is left unchanged.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>The updated model.</returns>
 public BigQueryModel Patch(Model resource, bool matchETag, PatchModelOptions options = null)
 {
     if (matchETag)
     {
         resource.ETag = Resource.ETag;
     }
     return(_client.PatchModel(Reference, resource, options));
 }
 /// <summary>
 /// Asynchronously patches this model with fields in the specified resource.
 /// </summary>
 /// <remarks>
 /// This method delegates to <see cref="BigQueryClient.PatchModelAsync(ModelReference, Model, PatchModelOptions, CancellationToken)"/>.
 /// </remarks>
 /// <param name="resource">The resource to patch with. Must not be null.</param>
 /// <param name="matchETag">If true, the etag from <see cref="Resource"/> is propagated into <paramref name="resource"/> for
 /// optimistic concurrency. Otherwise, <paramref name="resource"/> is left unchanged.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result is
 /// the updated model.</returns>
 public Task <BigQueryModel> PatchAsync(Model resource, bool matchETag, PatchModelOptions options = null, CancellationToken cancellationToken = default)
 {
     if (matchETag)
     {
         resource.ETag = Resource.ETag;
     }
     return(_client.PatchModelAsync(Reference, resource, options, cancellationToken));
 }
 /// <summary>
 /// Asynchronously patches the specified model with fields in the given resource.
 /// </summary>
 /// <remarks>
 /// If the resource contains an ETag, it is used for optimistic concurrency validation.
 /// </remarks>
 /// <param name="modelReference">A fully-qualified identifier for the model. Must not be null.</param>
 /// <param name="resource">The model resource representation to use for the patch. Only fields present in the resource will be updated.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result is
 /// the updated model.</returns>
 public virtual Task <BigQueryModel> PatchModelAsync(ModelReference modelReference, Model resource, PatchModelOptions options = null, CancellationToken cancellationToken = default) =>
 throw new NotImplementedException();
 /// <summary>
 /// Asynchronously patches the specified model with fields in the given resource.
 /// This method just creates a <see cref="ModelReference"/> and delegates to <see cref="PatchModelAsync(ModelReference, Model, PatchModelOptions, CancellationToken)"/>.
 /// </summary>
 /// <remarks>
 /// If the resource contains an ETag, it is used for optimistic concurrency validation.
 /// </remarks>
 /// <param name="projectId">The project ID. Must not be null.</param>
 /// <param name="datasetId">The dataset ID. Must not be null.</param>
 /// <param name="modelId">The model ID. Must not be null.</param>
 /// <param name="resource">The model resource representation to use for the patch. Only fields present in the resource will be updated.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
 /// <returns>A task representing the asynchronous operation. When complete, the result is
 /// the updated model.</returns>
 public virtual Task <BigQueryModel> PatchModelAsync(string projectId, string datasetId, string modelId, Model resource, PatchModelOptions options = null, CancellationToken cancellationToken = default) =>
 PatchModelAsync(GetModelReference(projectId, datasetId, modelId), resource, options, cancellationToken);
 /// <summary>
 /// Patches the specified model with fields in the given resource.
 /// </summary>
 /// <remarks>
 /// If the resource contains an ETag, it is used for optimistic concurrency validation.
 /// </remarks>
 /// <param name="modelReference">A fully-qualified identifier for the model. Must not be null.</param>
 /// <param name="resource">The model resource representation to use for the patch. Only fields present in the resource will be updated.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>The updated model.</returns>
 public virtual BigQueryModel PatchModel(ModelReference modelReference, Model resource, PatchModelOptions options = null) =>
 throw new NotImplementedException();
 /// <summary>
 /// Patches the specified model with fields in the given resource.
 /// This method just creates a <see cref="ModelReference"/> and delegates to <see cref="PatchModel(ModelReference, Model, PatchModelOptions)"/>.
 /// </summary>
 /// <remarks>
 /// If the resource contains an ETag, it is used for optimistic concurrency validation.
 /// </remarks>
 /// <param name="projectId">The project ID. Must not be null.</param>
 /// <param name="datasetId">The dataset ID. Must not be null.</param>
 /// <param name="modelId">The model ID. Must not be null.</param>
 /// <param name="resource">The model resource representation to use for the patch. Only fields present in the resource will be updated.</param>
 /// <param name="options">The options for the operation. May be null, in which case defaults will be supplied.</param>
 /// <returns>The updated model.</returns>
 public virtual BigQueryModel PatchModel(string projectId, string datasetId, string modelId, Model resource, PatchModelOptions options = null) =>
 PatchModel(GetModelReference(projectId, datasetId, modelId), resource, options);
        /// <inheritdoc />
        public override async Task <BigQueryModel> PatchModelAsync(ModelReference modelReference, Model resource, PatchModelOptions options = null, CancellationToken cancellationToken = default)
        {
            var request = CreatePatchModelRequest(modelReference, resource, options);
            var model   = await request.ExecuteAsync().ConfigureAwait(false);

            return(new BigQueryModel(this, model));
        }
        /// <inheritdoc />
        public override BigQueryModel PatchModel(ModelReference modelReference, Model resource, PatchModelOptions options = null)
        {
            var request = CreatePatchModelRequest(modelReference, resource, options);
            var model   = request.Execute();

            return(new BigQueryModel(this, model));
        }
        private PatchRequest CreatePatchModelRequest(ModelReference modelReference, Model resource, PatchModelOptions options)
        {
            GaxPreconditions.CheckNotNull(modelReference, nameof(modelReference));
            GaxPreconditions.CheckNotNull(resource, nameof(resource));
            var request = Service.Models.Patch(resource, modelReference.ProjectId, modelReference.DatasetId, modelReference.ModelId);

            options?.ModifyRequest(request);
            RetryIfETagPresent(request, resource);
            return(request);
        }