/* tslint:disable */
/* eslint-disable */
/**
 * Ringer Business API
 * This API provides comprehensive endpoints for the Ringer Business system. It includes functionality for managing customer accounts, addresses, sites, phone numbers, payments, users, and other business resources.  Operations typically require authentication and appropriate permissions. 
 *
 * The version of the OpenAPI document: 1.0.6
 * Contact: support@ringer.tel
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


import * as runtime from '../runtime';
import type {
  AddressResponse,
  AddressUpdateRequest,
  ComponentsSchemasError,
} from '../models/index';
import {
    AddressResponseFromJSON,
    AddressResponseToJSON,
    AddressUpdateRequestFromJSON,
    AddressUpdateRequestToJSON,
    ComponentsSchemasErrorFromJSON,
    ComponentsSchemasErrorToJSON,
} from '../models/index';

export interface GetAccountAddressRequest {
    id: number;
}

export interface UpdateAccountAddressRequest {
    id: number;
    addressUpdateRequest: AddressUpdateRequest;
}

/**
 * 
 */
export class AddressesApi extends runtime.BaseAPI {

    /**
     * Fetch the address record by its ID. 
     * Get an Address
     */
    async getAccountAddressRaw(requestParameters: GetAccountAddressRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<AddressResponse>> {
        if (requestParameters['id'] == null) {
            throw new runtime.RequiredError(
                'id',
                'Required parameter "id" was null or undefined when calling getAccountAddress().'
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            // oauth required
            headerParameters["Authorization"] = await this.configuration.accessToken("oAuth2", []);
        }

        const response = await this.request({
            path: `/addresses/{id}`.replace(`{${"id"}}`, encodeURIComponent(String(requestParameters['id']))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.JSONApiResponse(response, (jsonValue) => AddressResponseFromJSON(jsonValue));
    }

    /**
     * Fetch the address record by its ID. 
     * Get an Address
     */
    async getAccountAddress(requestParameters: GetAccountAddressRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<AddressResponse> {
        const response = await this.getAccountAddressRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Updates the details of a specific address record by its ID. This is typically used to modify the contact or billing address associated with an account. The user must have permissions to update the account to which this address belongs. 
     * Update an Address
     */
    async updateAccountAddressRaw(requestParameters: UpdateAccountAddressRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<AddressResponse>> {
        if (requestParameters['id'] == null) {
            throw new runtime.RequiredError(
                'id',
                'Required parameter "id" was null or undefined when calling updateAccountAddress().'
            );
        }

        if (requestParameters['addressUpdateRequest'] == null) {
            throw new runtime.RequiredError(
                'addressUpdateRequest',
                'Required parameter "addressUpdateRequest" was null or undefined when calling updateAccountAddress().'
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        headerParameters['Content-Type'] = 'application/json';

        if (this.configuration && this.configuration.accessToken) {
            // oauth required
            headerParameters["Authorization"] = await this.configuration.accessToken("oAuth2", []);
        }

        const response = await this.request({
            path: `/addresses/{id}`.replace(`{${"id"}}`, encodeURIComponent(String(requestParameters['id']))),
            method: 'PUT',
            headers: headerParameters,
            query: queryParameters,
            body: AddressUpdateRequestToJSON(requestParameters['addressUpdateRequest']),
        }, initOverrides);

        return new runtime.JSONApiResponse(response, (jsonValue) => AddressResponseFromJSON(jsonValue));
    }

    /**
     * Updates the details of a specific address record by its ID. This is typically used to modify the contact or billing address associated with an account. The user must have permissions to update the account to which this address belongs. 
     * Update an Address
     */
    async updateAccountAddress(requestParameters: UpdateAccountAddressRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<AddressResponse> {
        const response = await this.updateAccountAddressRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
