/*
 * 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 { AppleMapping } 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 {
  AppleMappingTestFlightGroupsOptionalParams,
  AppleMappingTestFlightGroupsResponse,
  AppleMappingGetOptionalParams,
  AppleMappingGetResponse,
  AppleMappingDeleteOptionalParams,
  Paths1B7RevxV01AppsOwnerNameAppNameAppleMappingPostRequestbodyContentApplicationJsonSchema,
  AppleMappingCreateOptionalParams,
  AppleMappingCreateResponse
} from "../models";

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

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

  /**
   * Fetch all apple test flight groups
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  testFlightGroups(
    ownerName: string,
    appName: string,
    options?: AppleMappingTestFlightGroupsOptionalParams
  ): Promise<AppleMappingTestFlightGroupsResponse> {
    return this.client.sendOperationRequest(
      { ownerName, appName, options },
      testFlightGroupsOperationSpec
    );
  }

  /**
   * Get mapping of apple app to an existing app in apple store.
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  get(
    ownerName: string,
    appName: string,
    options?: AppleMappingGetOptionalParams
  ): Promise<AppleMappingGetResponse> {
    return this.client.sendOperationRequest(
      { ownerName, appName, options },
      getOperationSpec
    );
  }

  /**
   * Delete mapping of apple app to an existing app in apple store.
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param options The options parameters.
   */
  delete(
    ownerName: string,
    appName: string,
    options?: AppleMappingDeleteOptionalParams
  ): Promise<void> {
    return this.client.sendOperationRequest(
      { ownerName, appName, options },
      deleteOperationSpec
    );
  }

  /**
   * Create a mapping for an existing app in apple store for the specified application.
   * @param ownerName The name of the owner
   * @param appName The name of the application
   * @param body The apple app mapping object
   * @param options The options parameters.
   */
  create(
    ownerName: string,
    appName: string,
    body: Paths1B7RevxV01AppsOwnerNameAppNameAppleMappingPostRequestbodyContentApplicationJsonSchema,
    options?: AppleMappingCreateOptionalParams
  ): Promise<AppleMappingCreateResponse> {
    return this.client.sendOperationRequest(
      { ownerName, appName, body, options },
      createOperationSpec
    );
  }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);

const testFlightGroupsOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/apple_test_flight_groups",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper: {
        type: {
          name: "Sequence",
          element: {
            type: {
              name: "Composite",
              className:
                "PathsZew5JgV01AppsOwnerNameAppNameAppleTestFlightGroupsGetResponses200ContentApplicationJsonSchemaItems"
            }
          }
        }
      }
    },
    default: {
      bodyMapper:
        Mappers.Paths11QoktgV01AppsOwnerNameAppNameAppleTestFlightGroupsGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [Parameters.$host, Parameters.ownerName, Parameters.appName],
  headerParameters: [Parameters.accept],
  serializer
};
const getOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/apple_mapping",
  httpMethod: "GET",
  responses: {
    200: {
      bodyMapper:
        Mappers.PathsH96V4UV01AppsOwnerNameAppNameAppleMappingGetResponses200ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.PathsU1IachV01AppsOwnerNameAppNameAppleMappingGetResponsesDefaultContentApplicationJsonSchema
    }
  },
  urlParameters: [Parameters.$host, Parameters.ownerName, Parameters.appName],
  headerParameters: [Parameters.accept],
  serializer
};
const deleteOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/apple_mapping",
  httpMethod: "DELETE",
  responses: {
    200: {},
    default: {
      bodyMapper:
        Mappers.Paths1F11J7YV01AppsOwnerNameAppNameAppleMappingDeleteResponsesDefaultContentApplicationJsonSchema
    }
  },
  requestBody: Parameters.body8,
  urlParameters: [Parameters.$host, Parameters.ownerName, Parameters.appName],
  headerParameters: [Parameters.contentType, Parameters.accept],
  mediaType: "json",
  serializer
};
const createOperationSpec: coreClient.OperationSpec = {
  path: "/v0.1/apps/{owner_name}/{app_name}/apple_mapping",
  httpMethod: "POST",
  responses: {
    201: {
      bodyMapper:
        Mappers.Paths1J6Tdl2V01AppsOwnerNameAppNameAppleMappingPostResponses201ContentApplicationJsonSchema
    },
    default: {
      bodyMapper:
        Mappers.PathsRxnoxxV01AppsOwnerNameAppNameAppleMappingPostResponsesDefaultContentApplicationJsonSchema
    }
  },
  requestBody: Parameters.body12,
  urlParameters: [Parameters.$host, Parameters.ownerName, Parameters.appName],
  headerParameters: [Parameters.contentType, Parameters.accept],
  mediaType: "json",
  serializer
};
