/* tslint:disable */
/* eslint-disable */
/**
 * UCX Proxy
 * A single use API for the UCX Proxy.
 *
 * The version of the OpenAPI document: 0.0.12
 * Contact: customersuccess@equisoft.com
 *
 * 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 {
  ContactResultSchema,
  ErrorSchema,
} from '../models/index';
import {
    ContactResultSchemaFromJSON,
    ContactResultSchemaToJSON,
    ErrorSchemaFromJSON,
    ErrorSchemaToJSON,
} from '../models/index';

export interface GetContactByIdRequest {
    uniqueIdentifier: string;
    organizationId?: string | null;
}

export interface SearchContactsRequest {
    name?: string | null;
    offset?: number | null;
    limit?: number | null;
    organizationId?: string | null;
}

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

    /**
     * Creates request options for getContactById without sending the request
     */
    async getContactByIdRequestOpts(requestParameters: GetContactByIdRequest): Promise<runtime.RequestOpts> {
        if (requestParameters['uniqueIdentifier'] == null) {
            throw new runtime.RequiredError(
                'uniqueIdentifier',
                'Required parameter "uniqueIdentifier" was null or undefined when calling getContactById().'
            );
        }

        const queryParameters: any = {};

        if (requestParameters['organizationId'] != null) {
            queryParameters['organizationId'] = requestParameters['organizationId'];
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            // oauth required
            const token = this.configuration.accessToken;
            const tokenString = await token("default", ["ucx:read"]);
            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }


        let urlPath = `/contacts/{uniqueIdentifier}`;
        urlPath = urlPath.replace(`{${"uniqueIdentifier"}}`, encodeURIComponent(String(requestParameters['uniqueIdentifier'])));

        return {
            path: urlPath,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        };
    }

    /**
     * Get contact by unique identifier
     */
    async getContactByIdRaw(requestParameters: GetContactByIdRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ContactResultSchema>> {
        const requestOptions = await this.getContactByIdRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Get contact by unique identifier
     */
    async getContactById(requestParameters: GetContactByIdRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ContactResultSchema> {
        const response = await this.getContactByIdRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Creates request options for searchContacts without sending the request
     */
    async searchContactsRequestOpts(requestParameters: SearchContactsRequest): Promise<runtime.RequestOpts> {
        const queryParameters: any = {};

        if (requestParameters['name'] != null) {
            queryParameters['name'] = requestParameters['name'];
        }

        if (requestParameters['offset'] != null) {
            queryParameters['offset'] = requestParameters['offset'];
        }

        if (requestParameters['limit'] != null) {
            queryParameters['limit'] = requestParameters['limit'];
        }

        if (requestParameters['organizationId'] != null) {
            queryParameters['organizationId'] = requestParameters['organizationId'];
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            // oauth required
            const token = this.configuration.accessToken;
            const tokenString = await token("default", ["ucx:read"]);
            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }


        let urlPath = `/contacts`;

        return {
            path: urlPath,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        };
    }

    /**
     * Search contacts for a specific organization
     */
    async searchContactsRaw(requestParameters: SearchContactsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ContactResultSchema>> {
        const requestOptions = await this.searchContactsRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Search contacts for a specific organization
     */
    async searchContacts(requestParameters: SearchContactsRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ContactResultSchema> {
        const response = await this.searchContactsRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
