/* 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 {
  CreateRoleRequest,
  RolePermissionsResponse,
  RoleResponse,
  UpdateRolePermissionsRequest,
} from '../models/index';
import {
    CreateRoleRequestFromJSON,
    CreateRoleRequestToJSON,
    RolePermissionsResponseFromJSON,
    RolePermissionsResponseToJSON,
    RoleResponseFromJSON,
    RoleResponseToJSON,
    UpdateRolePermissionsRequestFromJSON,
    UpdateRolePermissionsRequestToJSON,
} from '../models/index';

export interface ApiRolesIdDeleteRequest {
    id: string;
}

export interface ApiRolesIdGetRequest {
    id: string;
}

export interface ApiRolesIdPermissionsPutRequest {
    id: string;
    updateRolePermissionsRequest?: UpdateRolePermissionsRequest;
}

export interface ApiRolesPostRequest {
    createRoleRequest?: CreateRoleRequest;
}

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

    /**
     */
    async apiRolesGetRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<RoleResponse>>> {
        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/roles`;

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

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

    /**
     */
    async apiRolesGet(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<RoleResponse>> {
        const response = await this.apiRolesGetRaw(initOverrides);
        return await response.value();
    }

    /**
     */
    async apiRolesIdDeleteRaw(requestParameters: ApiRolesIdDeleteRequest, 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 apiRolesIdDelete().'
            );
        }

        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/roles/{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 apiRolesIdDelete(requestParameters: ApiRolesIdDeleteRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.apiRolesIdDeleteRaw(requestParameters, initOverrides);
    }

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

        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/roles/{id}`;
        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.JSONApiResponse(response, (jsonValue) => RolePermissionsResponseFromJSON(jsonValue));
    }

    /**
     */
    async apiRolesIdGet(requestParameters: ApiRolesIdGetRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<RolePermissionsResponse> {
        const response = await this.apiRolesIdGetRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async apiRolesIdPermissionsPutRaw(requestParameters: ApiRolesIdPermissionsPutRequest, 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 apiRolesIdPermissionsPut().'
            );
        }

        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/roles/{id}/permissions`;
        urlPath = urlPath.replace(`{${"id"}}`, encodeURIComponent(String(requestParameters['id'])));

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

        return new runtime.VoidApiResponse(response);
    }

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

    /**
     */
    async apiRolesPostRaw(requestParameters: ApiRolesPostRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<RoleResponse>> {
        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/roles`;

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

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

    /**
     */
    async apiRolesPost(requestParameters: ApiRolesPostRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<RoleResponse> {
        const response = await this.apiRolesPostRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
