/* 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.
 */
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import * as runtime from '../runtime';
import { CreatePayloadSourceAuthenticationSchemaToJSON, ListOrganizationSourceAuthenticationResultSchemaFromJSON, OrganizationSourceAuthenticationResultSchemaFromJSON, ToggleSourceAuthenticationSchemaToJSON, UpdatePayloadSourceAuthenticationSchemaToJSON, } from '../models/index';
/**
 *
 */
export class OrganizationSourceAuthenticationApi extends runtime.BaseAPI {
    /**
     * Creates request options for createOrganizationSource without sending the request
     */
    createOrganizationSourceRequestOpts(requestParameters) {
        return __awaiter(this, void 0, void 0, function* () {
            if (requestParameters['organizationId'] == null) {
                throw new runtime.RequiredError('organizationId', 'Required parameter "organizationId" was null or undefined when calling createOrganizationSource().');
            }
            if (requestParameters['payload'] == null) {
                throw new runtime.RequiredError('payload', 'Required parameter "payload" was null or undefined when calling createOrganizationSource().');
            }
            const queryParameters = {};
            const headerParameters = {};
            if (this.configuration && this.configuration.accessToken) {
                // oauth required
                const token = this.configuration.accessToken;
                const tokenString = yield token("default", ["ucx:organization"]);
                if (tokenString) {
                    headerParameters["Authorization"] = `Bearer ${tokenString}`;
                }
            }
            const consumes = [
                { contentType: 'multipart/form-data' },
            ];
            // @ts-ignore: canConsumeForm may be unused
            const canConsumeForm = runtime.canConsumeForm(consumes);
            let formParams;
            let useForm = false;
            // use FormData to transmit files using content-type "multipart/form-data"
            useForm = canConsumeForm;
            if (useForm) {
                formParams = new FormData();
            }
            else {
                formParams = new URLSearchParams();
            }
            if (requestParameters['payload'] != null) {
                formParams.append('payload', new Blob([JSON.stringify(CreatePayloadSourceAuthenticationSchemaToJSON(requestParameters['payload']))], { type: "application/json", }));
            }
            if (requestParameters['certificate'] != null) {
                formParams.append('certificate', requestParameters['certificate']);
            }
            let urlPath = `/authentications/organizations/{organizationId}/sources`;
            urlPath = urlPath.replace(`{${"organizationId"}}`, encodeURIComponent(String(requestParameters['organizationId'])));
            return {
                path: urlPath,
                method: 'POST',
                headers: headerParameters,
                query: queryParameters,
                body: formParams,
            };
        });
    }
    /**
     * Create a new source for an organization and authenticate
     */
    createOrganizationSourceRaw(requestParameters, initOverrides) {
        return __awaiter(this, void 0, void 0, function* () {
            const requestOptions = yield this.createOrganizationSourceRequestOpts(requestParameters);
            const response = yield this.request(requestOptions, initOverrides);
            return new runtime.JSONApiResponse(response, (jsonValue) => OrganizationSourceAuthenticationResultSchemaFromJSON(jsonValue));
        });
    }
    /**
     * Create a new source for an organization and authenticate
     */
    createOrganizationSource(requestParameters, initOverrides) {
        return __awaiter(this, void 0, void 0, function* () {
            const response = yield this.createOrganizationSourceRaw(requestParameters, initOverrides);
            return yield response.value();
        });
    }
    /**
     * Creates request options for deleteOrganizationSource without sending the request
     */
    deleteOrganizationSourceRequestOpts(requestParameters) {
        return __awaiter(this, void 0, void 0, function* () {
            if (requestParameters['organizationId'] == null) {
                throw new runtime.RequiredError('organizationId', 'Required parameter "organizationId" was null or undefined when calling deleteOrganizationSource().');
            }
            if (requestParameters['sourceKey'] == null) {
                throw new runtime.RequiredError('sourceKey', 'Required parameter "sourceKey" was null or undefined when calling deleteOrganizationSource().');
            }
            const queryParameters = {};
            const headerParameters = {};
            if (this.configuration && this.configuration.accessToken) {
                // oauth required
                const token = this.configuration.accessToken;
                const tokenString = yield token("default", ["ucx:organization"]);
                if (tokenString) {
                    headerParameters["Authorization"] = `Bearer ${tokenString}`;
                }
            }
            let urlPath = `/authentications/organizations/{organizationId}/sources/{sourceKey}`;
            urlPath = urlPath.replace(`{${"organizationId"}}`, encodeURIComponent(String(requestParameters['organizationId'])));
            urlPath = urlPath.replace(`{${"sourceKey"}}`, encodeURIComponent(String(requestParameters['sourceKey'])));
            return {
                path: urlPath,
                method: 'DELETE',
                headers: headerParameters,
                query: queryParameters,
            };
        });
    }
    /**
     * Delete an existing source
     */
    deleteOrganizationSourceRaw(requestParameters, initOverrides) {
        return __awaiter(this, void 0, void 0, function* () {
            const requestOptions = yield this.deleteOrganizationSourceRequestOpts(requestParameters);
            const response = yield this.request(requestOptions, initOverrides);
            return new runtime.VoidApiResponse(response);
        });
    }
    /**
     * Delete an existing source
     */
    deleteOrganizationSource(requestParameters, initOverrides) {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.deleteOrganizationSourceRaw(requestParameters, initOverrides);
        });
    }
    /**
     * Creates request options for listOrganizationSources without sending the request
     */
    listOrganizationSourcesRequestOpts(requestParameters) {
        return __awaiter(this, void 0, void 0, function* () {
            if (requestParameters['organizationId'] == null) {
                throw new runtime.RequiredError('organizationId', 'Required parameter "organizationId" was null or undefined when calling listOrganizationSources().');
            }
            const queryParameters = {};
            const headerParameters = {};
            if (this.configuration && this.configuration.accessToken) {
                // oauth required
                const token = this.configuration.accessToken;
                const tokenString = yield token("default", ["ucx:organization"]);
                if (tokenString) {
                    headerParameters["Authorization"] = `Bearer ${tokenString}`;
                }
            }
            let urlPath = `/authentications/organizations/{organizationId}/sources`;
            urlPath = urlPath.replace(`{${"organizationId"}}`, encodeURIComponent(String(requestParameters['organizationId'])));
            return {
                path: urlPath,
                method: 'GET',
                headers: headerParameters,
                query: queryParameters,
            };
        });
    }
    /**
     * Get all the authentication sources for an organization
     */
    listOrganizationSourcesRaw(requestParameters, initOverrides) {
        return __awaiter(this, void 0, void 0, function* () {
            const requestOptions = yield this.listOrganizationSourcesRequestOpts(requestParameters);
            const response = yield this.request(requestOptions, initOverrides);
            return new runtime.JSONApiResponse(response, (jsonValue) => ListOrganizationSourceAuthenticationResultSchemaFromJSON(jsonValue));
        });
    }
    /**
     * Get all the authentication sources for an organization
     */
    listOrganizationSources(requestParameters, initOverrides) {
        return __awaiter(this, void 0, void 0, function* () {
            const response = yield this.listOrganizationSourcesRaw(requestParameters, initOverrides);
            return yield response.value();
        });
    }
    /**
     * Creates request options for toggleOrganizationSource without sending the request
     */
    toggleOrganizationSourceRequestOpts(requestParameters) {
        return __awaiter(this, void 0, void 0, function* () {
            if (requestParameters['organizationId'] == null) {
                throw new runtime.RequiredError('organizationId', 'Required parameter "organizationId" was null or undefined when calling toggleOrganizationSource().');
            }
            if (requestParameters['sourceKey'] == null) {
                throw new runtime.RequiredError('sourceKey', 'Required parameter "sourceKey" was null or undefined when calling toggleOrganizationSource().');
            }
            if (requestParameters['toggleSourceAuthenticationSchema'] == null) {
                throw new runtime.RequiredError('toggleSourceAuthenticationSchema', 'Required parameter "toggleSourceAuthenticationSchema" was null or undefined when calling toggleOrganizationSource().');
            }
            const queryParameters = {};
            const headerParameters = {};
            headerParameters['Content-Type'] = 'application/json';
            if (this.configuration && this.configuration.accessToken) {
                // oauth required
                const token = this.configuration.accessToken;
                const tokenString = yield token("default", ["ucx:organization"]);
                if (tokenString) {
                    headerParameters["Authorization"] = `Bearer ${tokenString}`;
                }
            }
            let urlPath = `/authentications/organizations/{organizationId}/sources/{sourceKey}/state`;
            urlPath = urlPath.replace(`{${"organizationId"}}`, encodeURIComponent(String(requestParameters['organizationId'])));
            urlPath = urlPath.replace(`{${"sourceKey"}}`, encodeURIComponent(String(requestParameters['sourceKey'])));
            return {
                path: urlPath,
                method: 'PUT',
                headers: headerParameters,
                query: queryParameters,
                body: ToggleSourceAuthenticationSchemaToJSON(requestParameters['toggleSourceAuthenticationSchema']),
            };
        });
    }
    /**
     * Enable or disable a given source for an organization
     */
    toggleOrganizationSourceRaw(requestParameters, initOverrides) {
        return __awaiter(this, void 0, void 0, function* () {
            const requestOptions = yield this.toggleOrganizationSourceRequestOpts(requestParameters);
            const response = yield this.request(requestOptions, initOverrides);
            return new runtime.JSONApiResponse(response, (jsonValue) => OrganizationSourceAuthenticationResultSchemaFromJSON(jsonValue));
        });
    }
    /**
     * Enable or disable a given source for an organization
     */
    toggleOrganizationSource(requestParameters, initOverrides) {
        return __awaiter(this, void 0, void 0, function* () {
            const response = yield this.toggleOrganizationSourceRaw(requestParameters, initOverrides);
            return yield response.value();
        });
    }
    /**
     * Creates request options for updateOrganizationSource without sending the request
     */
    updateOrganizationSourceRequestOpts(requestParameters) {
        return __awaiter(this, void 0, void 0, function* () {
            if (requestParameters['organizationId'] == null) {
                throw new runtime.RequiredError('organizationId', 'Required parameter "organizationId" was null or undefined when calling updateOrganizationSource().');
            }
            if (requestParameters['sourceKey'] == null) {
                throw new runtime.RequiredError('sourceKey', 'Required parameter "sourceKey" was null or undefined when calling updateOrganizationSource().');
            }
            if (requestParameters['payload'] == null) {
                throw new runtime.RequiredError('payload', 'Required parameter "payload" was null or undefined when calling updateOrganizationSource().');
            }
            const queryParameters = {};
            const headerParameters = {};
            if (this.configuration && this.configuration.accessToken) {
                // oauth required
                const token = this.configuration.accessToken;
                const tokenString = yield token("default", ["ucx:organization"]);
                if (tokenString) {
                    headerParameters["Authorization"] = `Bearer ${tokenString}`;
                }
            }
            const consumes = [
                { contentType: 'multipart/form-data' },
            ];
            // @ts-ignore: canConsumeForm may be unused
            const canConsumeForm = runtime.canConsumeForm(consumes);
            let formParams;
            let useForm = false;
            // use FormData to transmit files using content-type "multipart/form-data"
            useForm = canConsumeForm;
            if (useForm) {
                formParams = new FormData();
            }
            else {
                formParams = new URLSearchParams();
            }
            if (requestParameters['payload'] != null) {
                formParams.append('payload', new Blob([JSON.stringify(UpdatePayloadSourceAuthenticationSchemaToJSON(requestParameters['payload']))], { type: "application/json", }));
            }
            if (requestParameters['certificate'] != null) {
                formParams.append('certificate', requestParameters['certificate']);
            }
            let urlPath = `/authentications/organizations/{organizationId}/sources/{sourceKey}`;
            urlPath = urlPath.replace(`{${"organizationId"}}`, encodeURIComponent(String(requestParameters['organizationId'])));
            urlPath = urlPath.replace(`{${"sourceKey"}}`, encodeURIComponent(String(requestParameters['sourceKey'])));
            return {
                path: urlPath,
                method: 'PUT',
                headers: headerParameters,
                query: queryParameters,
                body: formParams,
            };
        });
    }
    /**
     * Update the credentials of a given source for an organization
     */
    updateOrganizationSourceRaw(requestParameters, initOverrides) {
        return __awaiter(this, void 0, void 0, function* () {
            const requestOptions = yield this.updateOrganizationSourceRequestOpts(requestParameters);
            const response = yield this.request(requestOptions, initOverrides);
            return new runtime.JSONApiResponse(response, (jsonValue) => OrganizationSourceAuthenticationResultSchemaFromJSON(jsonValue));
        });
    }
    /**
     * Update the credentials of a given source for an organization
     */
    updateOrganizationSource(requestParameters, initOverrides) {
        return __awaiter(this, void 0, void 0, function* () {
            const response = yield this.updateOrganizationSourceRaw(requestParameters, initOverrides);
            return yield response.value();
        });
    }
}
