/*
 * 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 { Crashes } 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 {
  CrashesGetAppVersionsOptionalParams,
  CrashesGetAppVersionsResponse,
  CrashesGetAppCrashesInfoOptionalParams,
  CrashesGetAppCrashesInfoResponse,
  CrashesListSessionLogsOptionalParams,
  CrashesListSessionLogsResponse,
  CrashesGetCrashTextAttachmentContentOptionalParams,
  CrashesGetCrashTextAttachmentContentResponse,
  CrashesGetCrashAttachmentLocationOptionalParams,
  CrashesGetCrashAttachmentLocationResponse,
  CrashesListAttachmentsOptionalParams,
  CrashesListAttachmentsResponse,
  CrashesGetStacktraceOptionalParams,
  CrashesGetStacktraceResponse,
  CrashesGetRawCrashLocationOptionalParams,
  CrashesGetRawCrashLocationResponse,
  CrashesGetNativeCrashDownloadOptionalParams,
  CrashesGetNativeCrashDownloadResponse,
  CrashesGetNativeCrashOptionalParams,
  CrashesGetNativeCrashResponse,
  CrashesGetOptionalParams,
  CrashesGetResponse,
  CrashesDeleteOptionalParams,
  CrashesDeleteResponse,
  CrashesListOptionalParams,
  CrashesListResponse
} from "../models";

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

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

  /**
   * Gets a list of application versions.
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  getAppVersions(
    ownerName: string,
    appName: string,
    options?: CrashesGetAppVersionsOptionalParams
  ): Promise<CrashesGetAppVersionsResponse> {
    return this.client.sendOperationRequest(
      { ownerName, appName, options },
      getAppVersionsOperationSpec
    );
  }

  /**
   * Gets whether the application has any crashes.
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  getAppCrashesInfo(
    ownerName: string,
    appName: string,
    options?: CrashesGetAppCrashesInfoOptionalParams
  ): Promise<CrashesGetAppCrashesInfoResponse> {
    return this.client.sendOperationRequest(
      { ownerName, appName, options },
      getAppCrashesInfoOperationSpec
    );
  }

  /**
   * Get session logs by crash ID
   * @param crashId The id of the a crash
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  listSessionLogs(
    crashId: string,
    ownerName: string,
    appName: string,
    options?: CrashesListSessionLogsOptionalParams
  ): Promise<CrashesListSessionLogsResponse> {
    return this.client.sendOperationRequest(
      { crashId, ownerName, appName, options },
      listSessionLogsOperationSpec
    );
  }

  /**
   * Gets content of the text attachment.
   * @param crashId id of a specific crash
   * @param attachmentId attachment id
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  getCrashTextAttachmentContent(
    crashId: string,
    attachmentId: string,
    ownerName: string,
    appName: string,
    options?: CrashesGetCrashTextAttachmentContentOptionalParams
  ): Promise<CrashesGetCrashTextAttachmentContentResponse> {
    return this.client.sendOperationRequest(
      { crashId, attachmentId, ownerName, appName, options },
      getCrashTextAttachmentContentOperationSpec
    );
  }

  /**
   * Gets the URI location to download crash attachment.
   * @param crashId id of a specific crash
   * @param attachmentId attachment id
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  getCrashAttachmentLocation(
    crashId: string,
    attachmentId: string,
    ownerName: string,
    appName: string,
    options?: CrashesGetCrashAttachmentLocationOptionalParams
  ): Promise<CrashesGetCrashAttachmentLocationResponse> {
    return this.client.sendOperationRequest(
      { crashId, attachmentId, ownerName, appName, options },
      getCrashAttachmentLocationOperationSpec
    );
  }

  /**
   * Gets all attachments for a specific crash.
   * @param crashId id of a specific crash
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  listAttachments(
    crashId: string,
    ownerName: string,
    appName: string,
    options?: CrashesListAttachmentsOptionalParams
  ): Promise<CrashesListAttachmentsResponse> {
    return this.client.sendOperationRequest(
      { crashId, ownerName, appName, options },
      listAttachmentsOperationSpec
    );
  }

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

  /**
   * Gets the URI location to download json of a specific crash.
   * @param crashGroupId id of a specific group
   * @param crashId id of a specific crash
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  getRawCrashLocation(
    crashGroupId: string,
    crashId: string,
    ownerName: string,
    appName: string,
    options?: CrashesGetRawCrashLocationOptionalParams
  ): Promise<CrashesGetRawCrashLocationResponse> {
    return this.client.sendOperationRequest(
      { crashGroupId, crashId, ownerName, appName, options },
      getRawCrashLocationOperationSpec
    );
  }

  /**
   * Gets the native log of a specific crash as a text attachment.
   * @param crashGroupId id of a specific group
   * @param crashId id of a specific crash
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  getNativeCrashDownload(
    crashGroupId: string,
    crashId: string,
    ownerName: string,
    appName: string,
    options?: CrashesGetNativeCrashDownloadOptionalParams
  ): Promise<CrashesGetNativeCrashDownloadResponse> {
    return this.client.sendOperationRequest(
      { crashGroupId, crashId, ownerName, appName, options },
      getNativeCrashDownloadOperationSpec
    );
  }

  /**
   * Gets the native log of a specific crash.
   * @param crashGroupId id of a specific group
   * @param crashId id of a specific crash
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  getNativeCrash(
    crashGroupId: string,
    crashId: string,
    ownerName: string,
    appName: string,
    options?: CrashesGetNativeCrashOptionalParams
  ): Promise<CrashesGetNativeCrashResponse> {
    return this.client.sendOperationRequest(
      { crashGroupId, crashId, ownerName, appName, options },
      getNativeCrashOperationSpec
    );
  }

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

  /**
   * Delete a specific crash and related attachments and blobs for an app.
   * @param crashGroupId id of a specific group
   * @param crashId id of a specific crash
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  delete(
    crashGroupId: string,
    crashId: string,
    ownerName: string,
    appName: string,
    options?: CrashesDeleteOptionalParams
  ): Promise<CrashesDeleteResponse> {
    return this.client.sendOperationRequest(
      { crashGroupId, crashId, ownerName, appName, options },
      deleteOperationSpec
    );
  }

  /**
   * Gets all crashes of 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.
   */
  list(
    crashGroupId: string,
    ownerName: string,
    appName: string,
    options?: CrashesListOptionalParams
  ): Promise<CrashesListResponse> {
    return this.client.sendOperationRequest(
      { crashGroupId, ownerName, appName, options },
      listOperationSpec
    );
  }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);

const getAppVersionsOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/versions",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: {
        type: {
          name: "Sequence",
          element: {
            type: {
              name: "Composite",
              className:
                "Paths1MuofruV01AppsOwnerNameAppNameVersionsGetResponses200ContentApplicationJsonSchemaItems"
            }
          }
        }
      }
    },
    default: {
      bodyMapper:
        Mappers.PathsDgnk0AV01AppsOwnerNameAppNameVersionsGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [Parameters.$host, Parameters.ownerName, Parameters.appName],
  headerParameters: [Parameters.accept],
  serializer
};
const getAppCrashesInfoOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/crashes_info",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper:
        Mappers.PathsA8ApyzV01AppsOwnerNameAppNameCrashesInfoGetResponses200ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.PathsBhrh3SV01AppsOwnerNameAppNameCrashesInfoGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [Parameters.$host, Parameters.ownerName, Parameters.appName],
  headerParameters: [Parameters.accept],
  serializer
};
const listSessionLogsOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/crashes/{crash_id}/session_logs",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper:
        Mappers.Paths1Ut4QauV01AppsOwnerNameAppNameCrashesCrashIdSessionLogsGetResponses200ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.PathsRtgrgxV01AppsOwnerNameAppNameCrashesCrashIdSessionLogsGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  queryParameters: [Parameters.date],
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const getCrashTextAttachmentContentOperationSpec: coreClient.OperationSpec = {
  path:
    "/v0.1/apps/{owner_name}/{app_name}/crashes/{crash_id}/attachments/{attachment_id}/text",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: { type: { name: "String" } }
    },
    default: {
      bodyMapper:
        Mappers.Paths2Myey8V01AppsOwnerNameAppNameCrashesCrashIdAttachmentsAttachmentIdTextGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashId,
    Parameters.attachmentId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const getCrashAttachmentLocationOperationSpec: coreClient.OperationSpec = {
  path:
    "/v0.1/apps/{owner_name}/{app_name}/crashes/{crash_id}/attachments/{attachment_id}/location",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper:
        Mappers.Paths1520RtwV01AppsOwnerNameAppNameCrashesCrashIdAttachmentsAttachmentIdLocationGetResponses200ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.PathsM7AdswV01AppsOwnerNameAppNameCrashesCrashIdAttachmentsAttachmentIdLocationGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashId,
    Parameters.attachmentId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const listAttachmentsOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/crashes/{crash_id}/attachments",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: {
        type: {
          name: "Sequence",
          element: {
            type: {
              name: "Composite",
              className:
                "Paths1Yzy65LV01AppsOwnerNameAppNameCrashesCrashIdAttachmentsGetResponses200ContentApplicationJsonSchemaItems"
            }
          }
        }
      }
    },
    default: {
      bodyMapper:
        Mappers.Paths1Kphy82V01AppsOwnerNameAppNameCrashesCrashIdAttachmentsGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const getStacktraceOperationSpec: coreClient.OperationSpec = {
  path:
    "/v0.1/apps/{owner_name}/{app_name}/crash_groups/{crash_group_id}/crashes/{crash_id}/stacktrace",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: Mappers.Stacktrace
    },
    default: {
      bodyMapper:
        Mappers.Paths1Ow10Y0V01AppsOwnerNameAppNameCrashGroupsCrashGroupIdCrashesCrashIdStacktraceGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  queryParameters: [Parameters.groupingOnly],
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashId,
    Parameters.crashGroupId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const getRawCrashLocationOperationSpec: coreClient.OperationSpec = {
  path:
    "/v0.1/apps/{owner_name}/{app_name}/crash_groups/{crash_group_id}/crashes/{crash_id}/raw/location",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper:
        Mappers.Paths5WkrbzV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdCrashesCrashIdRawLocationGetResponses200ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.Paths1Ft0W9TV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdCrashesCrashIdRawLocationGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashId,
    Parameters.crashGroupId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const getNativeCrashDownloadOperationSpec: coreClient.OperationSpec = {
  path:
    "/v0.1/apps/{owner_name}/{app_name}/crash_groups/{crash_group_id}/crashes/{crash_id}/native/download",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: { type: { name: "String" } }
    },
    default: {
      bodyMapper:
        Mappers.Paths1Oul3BhV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdCrashesCrashIdNativeDownloadGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashId,
    Parameters.crashGroupId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const getNativeCrashOperationSpec: coreClient.OperationSpec = {
  path:
    "/v0.1/apps/{owner_name}/{app_name}/crash_groups/{crash_group_id}/crashes/{crash_id}/native",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: { type: { name: "String" } }
    },
    default: {
      bodyMapper:
        Mappers.PathsFd64KmV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdCrashesCrashIdNativeGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashId,
    Parameters.crashGroupId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const getOperationSpec: coreClient.OperationSpec = {
  path:
    "/v0.1/apps/{owner_name}/{app_name}/crash_groups/{crash_group_id}/crashes/{crash_id}",
  httpMethod: "GET",
  responses: {
    201: {
      bodyMapper: Mappers.Crash
    },
    default: {
      bodyMapper:
        Mappers.Paths13Dx2ZcV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdCrashesCrashIdGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  queryParameters: [
    Parameters.groupingOnly,
    Parameters.includeReport,
    Parameters.includeLog,
    Parameters.includeDetails,
    Parameters.includeStacktrace
  ],
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashId,
    Parameters.crashGroupId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const deleteOperationSpec: coreClient.OperationSpec = {
  path:
    "/v0.1/apps/{owner_name}/{app_name}/crash_groups/{crash_group_id}/crashes/{crash_id}",
  httpMethod: "DELETE",
  responses: {
    200: {
      bodyMapper:
        Mappers.Paths10HkftV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdCrashesCrashIdDeleteResponses200ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.PathsL75Q9YV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdCrashesCrashIdDeleteResponsesDefaultContentApplicationJsonSchema
    }
  },
  queryParameters: [Parameters.retentionDelete],
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashId,
    Parameters.crashGroupId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
const listOperationSpec: coreClient.OperationSpec = {
  path:
    "/v0.1/apps/{owner_name}/{app_name}/crash_groups/{crash_group_id}/crashes",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: {
        type: {
          name: "Sequence",
          element: { type: { name: "Composite", className: "Crash" } }
        }
      }
    },
    default: {
      bodyMapper:
        Mappers.Paths1U57JmnV01AppsOwnerNameAppNameCrashGroupsCrashGroupIdCrashesGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  queryParameters: [
    Parameters.includeReport,
    Parameters.includeLog,
    Parameters.dateFrom,
    Parameters.dateTo,
    Parameters.appVersion1,
    Parameters.errorType
  ],
  urlParameters: [
    Parameters.$host,
    Parameters.ownerName,
    Parameters.appName,
    Parameters.crashGroupId
  ],
  headerParameters: [Parameters.accept],
  serializer
};
