/* 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 {
  ErrorSchema,
  ListUserSourceAuthenticationResultSchema,
  UpdatePayloadUserSourceAuthenticationSchema,
  UserSourceAuthenticationResultSchema,
} from '../models/index';
import {
    ErrorSchemaFromJSON,
    ErrorSchemaToJSON,
    ListUserSourceAuthenticationResultSchemaFromJSON,
    ListUserSourceAuthenticationResultSchemaToJSON,
    UpdatePayloadUserSourceAuthenticationSchemaFromJSON,
    UpdatePayloadUserSourceAuthenticationSchemaToJSON,
    UserSourceAuthenticationResultSchemaFromJSON,
    UserSourceAuthenticationResultSchemaToJSON,
} from '../models/index';

export interface ListUserSourceAuthenticationRequest {
    userId: string;
}

export interface UpdateUserSourceAuthenticationRequest {
    userId: string;
    sourceKey: string;
    updatePayloadUserSourceAuthenticationSchema: UpdatePayloadUserSourceAuthenticationSchema;
}

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

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

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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


        let urlPath = `/authentications/users/{userId}/sources`;
        urlPath = urlPath.replace(`{${"userId"}}`, encodeURIComponent(String(requestParameters['userId'])));

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

    /**
     * Get all the available data sources for an user
     */
    async listUserSourceAuthenticationRaw(requestParameters: ListUserSourceAuthenticationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ListUserSourceAuthenticationResultSchema>> {
        const requestOptions = await this.listUserSourceAuthenticationRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Get all the available data sources for an user
     */
    async listUserSourceAuthentication(requestParameters: ListUserSourceAuthenticationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ListUserSourceAuthenticationResultSchema> {
        const response = await this.listUserSourceAuthenticationRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

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

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

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

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


        let urlPath = `/authentications/users/{userId}/sources/{sourceKey}`;
        urlPath = urlPath.replace(`{${"userId"}}`, encodeURIComponent(String(requestParameters['userId'])));
        urlPath = urlPath.replace(`{${"sourceKey"}}`, encodeURIComponent(String(requestParameters['sourceKey'])));

        return {
            path: urlPath,
            method: 'PUT',
            headers: headerParameters,
            query: queryParameters,
            body: UpdatePayloadUserSourceAuthenticationSchemaToJSON(requestParameters['updatePayloadUserSourceAuthenticationSchema']),
        };
    }

    /**
     * Update the credentials of a given source for a user
     */
    async updateUserSourceAuthenticationRaw(requestParameters: UpdateUserSourceAuthenticationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<UserSourceAuthenticationResultSchema>> {
        const requestOptions = await this.updateUserSourceAuthenticationRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Update the credentials of a given source for a user
     */
    async updateUserSourceAuthentication(requestParameters: UpdateUserSourceAuthenticationRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<UserSourceAuthenticationResultSchema> {
        const response = await this.updateUserSourceAuthenticationRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
