﻿/*
 * Copyright 2015 Google Inc
 *
 * Licensed under the Apache License, Version 2.0(the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

using System;
using Google.Apis.Dfareporting.v2_0;
using Google.Apis.Dfareporting.v2_0.Data;

namespace DfaReporting.Samples {
  /// <summary>
  /// This example illustrates how to patch a standard report. Patching a
  /// report will modify only the fields you specify.
  ///
  /// Tags: reports.patch
  /// </summary>
  class PatchReport : SampleBase {
    /// <summary>
    /// Returns a description about the code example.
    /// </summary>
    public override string Description {
      get {
        return "This example illustrates how to patch a standard report." +
            " Patching a report will modify only the fields you specify.\n";
      }
    }

    /// <summary>
    /// Main method, to run this code example as a standalone application.
    /// </summary>
    /// <param name="args">The command line arguments.</param>
    public static void Main(string[] args) {
      SampleBase codeExample = new PatchReport();
      Console.WriteLine(codeExample.Description);
      codeExample.Run(DfaReportingFactory.getInstance());
    }

    /// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="service">An initialized Dfa Reporting service object
    /// </param>
    public override void Run(DfareportingService service) {
      long reportId = long.Parse(_T("INSERT_REPORT_ID_HERE"));
      long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

      String reportName = _T("ENTER_REPORT_NAME_HERE");

      // Prepare the report object to patch.
      Report toPatch = new Report();
      // We only want to modify the report name.
      toPatch.Name = reportName;

      // Insert the report.
      Report report = service.Reports.Patch(toPatch, profileId, reportId).Execute();

      Console.WriteLine("{0} report with ID {1} was successfully patched.",
          report.Type, report.Id);
    }
  }
}
