/*
 * 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 { CrashGroups } 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 {
  CrashGroupsGetStacktraceOptionalParams,
  CrashGroupsGetStacktraceResponse,
  CrashGroupsGetOptionalParams,
  CrashGroupsGetResponse,
  CrashGroupsUpdateOptionalParams,
  CrashGroupsUpdateResponse,
  CrashGroupsListOptionalParams,
  CrashGroupsListResponse
} from "../models";

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

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

  /**
   * Gets a stacktrace for a specific crash.
   * @param crashGroupId id of a specific group
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  getStacktrace(
    crashGroupId: string,
    ownerName: string,
    appName: string,
    options?: CrashGroupsGetStacktraceOptionalParams
  ): Promise<CrashGroupsGetStacktraceResponse> {
    return this.client.sendOperationRequest(
      { crashGroupId, ownerName, appName, options },
      getStacktraceOperationSpec
    );
  }

  /**
   * Gets a specific group.
   * @param crashGroupId id of a specific group
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  get(
    crashGroupId: string,
    ownerName: string,
    appName: string,
    options?: CrashGroupsGetOptionalParams
  ): Promise<CrashGroupsGetResponse> {
    return this.client.sendOperationRequest(
      { crashGroupId, ownerName, appName, options },
      getOperationSpec
    );
  }

  /**
   * Updates a group.
   * @param crashGroupId id of a specific group
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  update(
    crashGroupId: string,
    ownerName: string,
    appName: string,
    options?: CrashGroupsUpdateOptionalParams
  ): Promise<CrashGroupsUpdateResponse> {
    return this.client.sendOperationRequest(
      { crashGroupId, ownerName, appName, options },
      updateOperationSpec
    );
  }

  /**
   * Gets a list of crash groups and whether the list contains all available groups.
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  list(
    ownerName: string,
    appName: string,
    options?: CrashGroupsListOptionalParams
  ): Promise<CrashGroupsListResponse> {
    return this.client.sendOperationRequest(
      { ownerName, appName, options },
      listOperationSpec
    );
  }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);

const getStacktraceOperationSpec: coreClient.OperationSpec = {
  path:
    "/v0.1/apps/{owner_name}/{app_name}/crash_groups/{crash_group_id}/stacktrace",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: Mappers.Stacktrace
    },
    default: {
      bodyMapper:
        Mappers.Paths11Adk1LV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdStacktraceGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  queryParameters: [Parameters.groupingOnly],
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashGroupId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const getOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/crash_groups/{crash_group_id}",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper:
        Mappers.PathsHnvr1EV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdGetResponses200ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.PathsNzisgxV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashGroupId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const updateOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/crash_groups/{crash_group_id}",
  httpMethod: "PATCH",
  responses: {
    200: {
      bodyMapper:
        Mappers.Paths6Qmpl3V01AppsOwnerNameAppNameCrashGroupsCrashGroupIdPatchResponses200ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.Paths1D54ZerV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdPatchResponsesDefaultContentApplicationJsonSchema
    }
  },
  requestBody: {
    parameterPath: {
      status: ["options", "status"],
      annotation: ["options", "annotation"]
    },
    mapper: {
      ...Mappers.PathsT60UxpV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdPatchRequestbodyContentApplicationJsonSchema,
      required: true
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashGroupId
  ],
  headerParameters: [Parameters.contentType, Parameters.accept],
  mediaType: "json",
  serializer
};
const listOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/crash_groups",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper:
        Mappers.PathsScc799V01AppsOwnerNameAppNameCrashGroupsGetResponses200ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.PathsFkuj51V01AppsOwnerNameAppNameCrashGroupsGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  queryParameters: [
    Parameters.appVersion1,
    Parameters.lastOccurrenceFrom,
    Parameters.lastOccurrenceTo,
    Parameters.groupType,
    Parameters.groupStatus,
    Parameters.groupTextSearch,
    Parameters.orderby1,
    Parameters.continuationToken
  ],
  urlParameters: [Parameters.$host, Parameters.ownerName, Parameters.appName],
  headerParameters: [Parameters.accept],
  serializer
};
