/**
 * Account information PNZ-API-CentreLib
 *
 * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
 */

import { ApiResponse, RequestOptions } from '../core';
import {
  AC9Checkaccountaccessconsentstatus,
  aC9CheckaccountaccessconsentstatusSchema,
} from '../models/aC9Checkaccountaccessconsentstatus';
import { string } from '../schema';
import { BaseController } from './baseController';

export class ConsentStatusController extends BaseController {
  /**
   * This request queries the most recently created account access consent whose id is specified in the
   * PNZ-T-AC-AccountAccessConsentId environment variable.
   * This step is placed here in the sequence because the status of the account-access-consents resource
   * will have changed from its original status at this point.
   *
   * Preconditions:
   *
   * *   This step relies on the presence of a PNZ-T-AC-AccountAccessToken environment variable, which is
   * set upon successful completion of Step AC1 - Initiate client credentials grant.
   * *   It also relies on the presence of a PNZ-T-AC-AccountAccessConsentId environment variable, which
   * is set upon successful completion of Step AC2 - Create account access consent.
   *
   *
   * Response:
   *
   * *   The response should be a single account-access-consent resource with the requested ConsentId.
   * *   The status of the account-access-consent is dynamic so the status returned may vary.
   *
   *
   * Postconditions:
   *
   * *   None
   *
   *
   * Examples:
   *
   * *   There is one example which shows the request and the expected response.
   *
   *
   * Troubleshooting:
   *
   * *   The most likely cause of errors is an expired access token. Complete Step AC1 - Initiate client
   * credentials grant before trying this request again.
   * *   Another likely cause is there is no PNZ-T-AC-AccountAccessConsentId environment variable.
   * Complete Step AC2 - Create account access consent before trying this request again.
   *
   * @param pNZTACAccountAccessConsentId
   * @return Response from the API call
   */
  async checkAccountAccessConsentStatus(
    pNZTACAccountAccessConsentId: string,
    requestOptions?: RequestOptions
  ): Promise<ApiResponse<AC9Checkaccountaccessconsentstatus>> {
    const req = this.createRequest('GET');
    const mapped = req.prepareArgs({
      pNZTACAccountAccessConsentId: [pNZTACAccountAccessConsentId, string()],
    });
    req.appendTemplatePath`/open-banking-nz/v2.3/account-access-consents/${mapped.pNZTACAccountAccessConsentId}`;
    return req.callAsJson(
      aC9CheckaccountaccessconsentstatusSchema,
      requestOptions
    );
  }
}
