/* tslint:disable */
/* eslint-disable */
/**
 * OmsorgCore.Api
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 1.0
 * 
 *
 * 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 {
  DocumentResponse,
  UpdateDocumentRequest,
} from '../models/index';
import {
    DocumentResponseFromJSON,
    DocumentResponseToJSON,
    UpdateDocumentRequestFromJSON,
    UpdateDocumentRequestToJSON,
} from '../models/index';

export interface ApiDocumentsGetRequest {
    entityType?: string;
    entityId?: string;
}

export interface ApiDocumentsIdDeleteRequest {
    id: string;
}

export interface ApiDocumentsIdDownloadGetRequest {
    id: string;
}

export interface ApiDocumentsIdPutRequest {
    id: string;
    updateDocumentRequest?: UpdateDocumentRequest;
}

export interface ApiDocumentsPostRequest {
    entityType?: string;
    entityId?: string;
    category?: string;
    description?: string;
    file?: Blob;
}

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

    /**
     */
    async apiDocumentsGetRaw(requestParameters: ApiDocumentsGetRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<DocumentResponse>>> {
        const queryParameters: any = {};

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

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

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = await token("Bearer", []);

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

        let urlPath = `/api/documents`;

        const response = await this.request({
            path: urlPath,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     */
    async apiDocumentsGet(requestParameters: ApiDocumentsGetRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<DocumentResponse>> {
        const response = await this.apiDocumentsGetRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async apiDocumentsIdDeleteRaw(requestParameters: ApiDocumentsIdDeleteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters['id'] == null) {
            throw new runtime.RequiredError(
                'id',
                'Required parameter "id" was null or undefined when calling apiDocumentsIdDelete().'
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = await token("Bearer", []);

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

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

        const response = await this.request({
            path: urlPath,
            method: 'DELETE',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     */
    async apiDocumentsIdDelete(requestParameters: ApiDocumentsIdDeleteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.apiDocumentsIdDeleteRaw(requestParameters, initOverrides);
    }

    /**
     */
    async apiDocumentsIdDownloadGetRaw(requestParameters: ApiDocumentsIdDownloadGetRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters['id'] == null) {
            throw new runtime.RequiredError(
                'id',
                'Required parameter "id" was null or undefined when calling apiDocumentsIdDownloadGet().'
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = await token("Bearer", []);

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

        let urlPath = `/api/documents/{id}/download`;
        urlPath = urlPath.replace(`{${"id"}}`, encodeURIComponent(String(requestParameters['id'])));

        const response = await this.request({
            path: urlPath,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     */
    async apiDocumentsIdDownloadGet(requestParameters: ApiDocumentsIdDownloadGetRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.apiDocumentsIdDownloadGetRaw(requestParameters, initOverrides);
    }

    /**
     */
    async apiDocumentsIdPutRaw(requestParameters: ApiDocumentsIdPutRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<DocumentResponse>> {
        if (requestParameters['id'] == null) {
            throw new runtime.RequiredError(
                'id',
                'Required parameter "id" was null or undefined when calling apiDocumentsIdPut().'
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = await token("Bearer", []);

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

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

        const response = await this.request({
            path: urlPath,
            method: 'PUT',
            headers: headerParameters,
            query: queryParameters,
            body: UpdateDocumentRequestToJSON(requestParameters['updateDocumentRequest']),
        }, initOverrides);

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

    /**
     */
    async apiDocumentsIdPut(requestParameters: ApiDocumentsIdPutRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<DocumentResponse> {
        const response = await this.apiDocumentsIdPutRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async apiDocumentsPostRaw(requestParameters: ApiDocumentsPostRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<DocumentResponse>> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = await token("Bearer", []);

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }
        const consumes: runtime.Consume[] = [
            { contentType: 'multipart/form-data' },
        ];
        // @ts-ignore: canConsumeForm may be unused
        const canConsumeForm = runtime.canConsumeForm(consumes);

        let formParams: { append(param: string, value: any): any };
        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['entityType'] != null) {
            formParams.append('EntityType', requestParameters['entityType'] as any);
        }

        if (requestParameters['entityId'] != null) {
            formParams.append('EntityId', requestParameters['entityId'] as any);
        }

        if (requestParameters['category'] != null) {
            formParams.append('Category', requestParameters['category'] as any);
        }

        if (requestParameters['description'] != null) {
            formParams.append('Description', requestParameters['description'] as any);
        }

        if (requestParameters['file'] != null) {
            formParams.append('File', requestParameters['file'] as any);
        }


        let urlPath = `/api/documents`;

        const response = await this.request({
            path: urlPath,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: formParams,
        }, initOverrides);

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

    /**
     */
    async apiDocumentsPost(requestParameters: ApiDocumentsPostRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<DocumentResponse> {
        const response = await this.apiDocumentsPostRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
