/*
 * Copyright (c) Microsoft Corporation.
 * Licensed under the MIT License.
 *
 * Code generated by Microsoft (R) AutoRest Code Generator.
 * Changes may cause incorrect behavior and will be lost if the code is regenerated.
 */

import { BugTracker } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { AppCenterClient } from "../appCenterClient";
import {
  BugTrackerGetRepoIssueFromCrashOptionalParams,
  BugTrackerGetRepoIssueFromCrashResponse,
  BugTrackerGetSettingsOptionalParams,
  BugTrackerGetSettingsResponse
} from "../models";

/** Class containing BugTracker operations. */
export class BugTrackerImpl implements BugTracker {
  private readonly client: AppCenterClient;

  /**
   * Initialize a new instance of the class BugTracker class.
   * @param client Reference to the service client
   */
  constructor(client: AppCenterClient) {
    this.client = client;
  }

  /**
   * Get project issue related to a crash group
   * @param crashGroupId CrashGroup Id
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  getRepoIssueFromCrash(
    crashGroupId: string,
    ownerName: string,
    appName: string,
    options?: BugTrackerGetRepoIssueFromCrashOptionalParams
  ): Promise<BugTrackerGetRepoIssueFromCrashResponse> {
    return this.client.sendOperationRequest(
      { crashGroupId, ownerName, appName, options },
      getRepoIssueFromCrashOperationSpec
    );
  }

  /**
   * Get bug tracker settings for a particular app
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  getSettings(
    ownerName: string,
    appName: string,
    options?: BugTrackerGetSettingsOptionalParams
  ): Promise<BugTrackerGetSettingsResponse> {
    return this.client.sendOperationRequest(
      { ownerName, appName, options },
      getSettingsOperationSpec
    );
  }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);

const getRepoIssueFromCrashOperationSpec: coreClient.OperationSpec = {
  path:
    "/v0.1/apps/{owner_name}/{app_name}/bugtracker/crashGroup/{crash_group_id}",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper:
        Mappers.Paths1G7Ul4DV01AppsOwnerNameAppNameBugtrackerCrashgroupCrashGroupIdGetResponses200ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.Paths1F8VktkV01AppsOwnerNameAppNameBugtrackerCrashgroupCrashGroupIdGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashGroupId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const getSettingsOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/bugtracker",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper:
        Mappers.Paths7O6EcbV01AppsOwnerNameAppNameBugtrackerGetResponses200ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.Paths3CngdnV01AppsOwnerNameAppNameBugtrackerGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [Parameters.$host, Parameters.ownerName, Parameters.appName],
  headerParameters: [Parameters.accept],
  serializer
};
