/**
 * PostNL Ecommerce APIsLib
 *
 * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
 */

import { ApiResponse, RequestOptions } from '../core';
import {
  ShippingstatusMethodNotAllowedError,
} from '../errors/shippingstatusMethodNotAllowedError';
import {
  ShippingstatusResponseError,
} from '../errors/shippingstatusResponseError';
import {
  ShippingstatusTooManyRequestError,
} from '../errors/shippingstatusTooManyRequestError';
import {
  ShippingstatusUnauthorizedError,
} from '../errors/shippingstatusUnauthorizedError';
import { LanguageEnum, languageEnumSchema } from '../models/languageEnum';
import {
  ShippingstatusResponse,
  shippingstatusResponseSchema,
} from '../models/shippingstatusResponse';
import {
  ShippingstatusResponseSignature,
  shippingstatusResponseSignatureSchema,
} from '../models/shippingstatusResponseSignature';
import {
  ShippingstatusResponseUpdatedShipment,
  shippingstatusResponseUpdatedShipmentSchema,
} from '../models/shippingstatusResponseUpdatedShipment';
import { array, boolean, optional, string } from '../schema';
import { BaseController } from './baseController';

export class TrackTraceController extends BaseController {
  /**
   * Request example:
   * ```
   * curl -X GET "https://api-sandbox.postnl.nl/shipment/v2/status/barcode/3SDEVC172649258" \
   * -H "Accept: application/json" \
   * -H "apikey: APIKEY-HERE" \
   * ```
   *
   *
   * @param barcode  Barcode of the shipment. This is a unique value.
   * @param detail   Option to include old statuses in the response
   * @param language Language of the returned shipment and status descriptions (default is Dutch).
   * @param maxDays  Limit the number of days that will be searched (decrease this amount for better
   *                                 performance).
   * @return Response from the API call
   */
  async returnsTheStatusesForAParticularBarcode(
    barcode: string,
    detail?: boolean,
    language?: LanguageEnum,
    maxDays?: string,
    requestOptions?: RequestOptions
  ): Promise<ApiResponse<ShippingstatusResponse>> {
    const req = this.createRequest('GET');
    const mapped = req.prepareArgs({
      barcode: [barcode, string()],
      detail: [detail, optional(boolean())],
      language: [language, optional(languageEnumSchema)],
      maxDays: [maxDays, optional(string())],
    });
    req.query('detail', mapped.detail);
    req.query('language', mapped.language);
    req.query('maxDays', mapped.maxDays);
    req.appendTemplatePath`/shipment/v2/status/barcode/${mapped.barcode}`;
    req.throwOn(400, ShippingstatusResponseError, 'Invalid request');
    req.throwOn(401, ShippingstatusUnauthorizedError, 'Invalid apikey');
    req.throwOn(405, ShippingstatusMethodNotAllowedError, 'Method not allowed');
    req.throwOn(429, ShippingstatusTooManyRequestError, 'Too many requests');
    req.throwOn(500, ShippingstatusResponseError, 'Internal server error');
    return req.callAsJson(shippingstatusResponseSchema, requestOptions);
  }

  /**
   * Request example:
   * ```
   * curl -X GET "https://api-sandbox.postnl.nl/shipment/v2/status/reference?
   * detail=true&language=NL&customerCode={{CustomerCode}}&customerNumber={{CustomerNumber}}&reference=RE
   * F98173245876329" \
   * -H "Accept: application/json" \
   * -H "apikey: APIKEY-HERE"
   * ```
   *
   *
   * @param customerCode   Customer code as known at PostNL Pakketten
   * @param customerNumber Customer number as known at PostNL Pakketten
   * @param referenceId    The customer reference belonging to the shipment
   * @param detail         Option to include old statuses in the response
   * @param language       Language of the returned shipment and status descriptions (default is
   *                                       Dutch).
   * @param maxDays        Limit the number of days that will be searched (decrease this amount for
   *                                       better performance). By default this is 90 days in the past.
   * @return Response from the API call
   */
  async getStatusInformationByCustomerReference(
    customerCode: string,
    customerNumber: string,
    referenceId: string,
    detail?: boolean,
    language?: LanguageEnum,
    maxDays?: string,
    requestOptions?: RequestOptions
  ): Promise<ApiResponse<ShippingstatusResponse>> {
    const req = this.createRequest('GET');
    const mapped = req.prepareArgs({
      customerCode: [customerCode, string()],
      customerNumber: [customerNumber, string()],
      referenceId: [referenceId, string()],
      detail: [detail, optional(boolean())],
      language: [language, optional(languageEnumSchema)],
      maxDays: [maxDays, optional(string())],
    });
    req.query('customerCode', mapped.customerCode);
    req.query('customerNumber', mapped.customerNumber);
    req.query('detail', mapped.detail);
    req.query('language', mapped.language);
    req.query('maxDays', mapped.maxDays);
    req.appendTemplatePath`/shipment/v2/status/reference/${mapped.referenceId}`;
    req.throwOn(400, ShippingstatusResponseError, 'Invalid request');
    req.throwOn(401, ShippingstatusUnauthorizedError, 'Invalid apikey');
    req.throwOn(405, ShippingstatusMethodNotAllowedError, 'Method not allowed');
    req.throwOn(429, ShippingstatusTooManyRequestError, 'Too many requests');
    req.throwOn(500, ShippingstatusResponseError, 'Internal server error');
    return req.callAsJson(shippingstatusResponseSchema, requestOptions);
  }

  /**
   * Request example:
   * ```
   * curl -X GET "https://api-sandbox.postnl.nl/shipment/v2/status/signature/3SDEVC172649258" \
   * -H "Accept: application/json" \
   * -H "apikey: APIKEY-HERE"
   * ```
   *
   *
   * @param barcode Barcode of the shipment
   * @return Response from the API call
   */
  async returnsTheSignatureOfAParticularShipment(
    barcode: string,
    requestOptions?: RequestOptions
  ): Promise<ApiResponse<ShippingstatusResponseSignature>> {
    const req = this.createRequest('GET');
    const mapped = req.prepareArgs({ barcode: [barcode, string()] });
    req.appendTemplatePath`/shipment/v2/status/signature/${mapped.barcode}`;
    req.throwOn(400, ShippingstatusResponseError, 'Invalid request');
    req.throwOn(401, ShippingstatusUnauthorizedError, 'Invalid apikey');
    req.throwOn(405, ShippingstatusMethodNotAllowedError, 'Method not allowed');
    req.throwOn(429, ShippingstatusTooManyRequestError, 'Too many requests');
    req.throwOn(500, ShippingstatusResponseError, 'Internal server error');
    return req.callAsJson(
      shippingstatusResponseSignatureSchema,
      requestOptions
    );
  }

  /**
   * Request example:
   * ```
   * curl -X GET "https://api-sandbox.postnl.nl/shipment/v2/status/11223344/updatedshipments?period=2022-
   * 12-25T10:00:00&amp;period=2022-12-25T10:12:00" \
   * -H "Accept: application/json" \
   * -H "apikey: APIKEY-HERE" \
   * ```
   *
   *
   * @param customernumber Your customer number
   * @param period         Optional array which defines a specific period in which to return updated
   *                                   shipments. For optimal results, schedule calls at a frequency between 5-15
   *                                   minutes and align the requested period accordingly to ensure complete coverage
   *                                   of past updates. Shorter periods yield improved response times. The API
   *                                   accommodates a maximum requested period of 2 hours, granting access to shipment
   *                                   data up to 48 hours in the past. Please use the following format: YYYY-MM-DDTHH:
   *                                   MM:SS and repeat this variable to define the period (e.g. /updatedshipments?
   *                                   period=2022-11-07T12:00:00.000&period=2022-11-07T12:05:00.000).
   * @return Response from the API call
   */
  async returnsTheUpdatedStatusesForAParticularCustomerNumber(
    customernumber: string,
    period?: string[],
    requestOptions?: RequestOptions
  ): Promise<ApiResponse<ShippingstatusResponseUpdatedShipment[]>> {
    const req = this.createRequest('GET');
    const mapped = req.prepareArgs({
      customernumber: [customernumber, string()],
      period: [period, optional(array(string()))],
    });
    req.query('period', mapped.period);
    req.appendTemplatePath`/shipment/v2/status/${mapped.customernumber}/updatedshipments`;
    req.throwOn(400, ShippingstatusResponseError, 'Invalid request');
    req.throwOn(401, ShippingstatusUnauthorizedError, 'Invalid apikey');
    req.throwOn(405, ShippingstatusMethodNotAllowedError, 'Method not allowed');
    req.throwOn(429, ShippingstatusTooManyRequestError, 'Too many requests');
    req.throwOn(500, ShippingstatusResponseError, 'Internal server error');
    return req.callAsJson(
      array(shippingstatusResponseUpdatedShipmentSchema),
      requestOptions
    );
  }
}
