/* tslint:disable */
/* eslint-disable */
/**
 * OpenAPI Petstore
 * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
 *
 * The version of the OpenAPI document: 1.0.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 {Api} from './index';
import {List} from 'immutable';
import {all, fork, put, takeLatest} from "redux-saga/effects";
import {apiCall, createSagaAction as originalCreateSagaAction, BaseEntitySupportPayloadApiAction, BasePayloadApiAction, NormalizedRecordEntities, normalizedEntities} from "../runtimeSagasAndRecords";
import {Action} from "redux-ts-simple";

import {
    GetBehaviorPermissionsResponse,
    GetBehaviorPermissionsResponseRecord,
    getBehaviorPermissionsResponseRecordUtils,
    GetBehaviorTypeResponse,
    GetBehaviorTypeResponseRecord,
    getBehaviorTypeResponseRecordUtils,
    BehaviorType,
} from '../models/index';

const createSagaAction = <T>(type: string) => originalCreateSagaAction<T>(type, {namespace: "api_behaviorApi"});

export const behaviorApiSagaMap = new Map<string, () => Generator<any, any, any>>([
        ["getBehaviorPermissions", getBehaviorPermissionsSaga],
        ["getBehaviorType", getBehaviorTypeSaga],
    ]
);

export function *behaviorApiAllSagas() {
    yield all([...behaviorApiSagaMap.values()].map(actionSaga => fork(actionSaga)));
}

//region getBehaviorPermissions

export interface PayloadGetBehaviorPermissions extends PayloadGetBehaviorPermissionsRequest, BasePayloadApiAction {
}

export interface PayloadGetBehaviorPermissionsRequest {
    behaviorId: string;
}

export const getBehaviorPermissionsRequest = createSagaAction<PayloadGetBehaviorPermissionsRequest>("getBehaviorPermissionsRequest");
export const getBehaviorPermissionsSuccess = createSagaAction<{ [key: string]: boolean; }>("getBehaviorPermissionsSuccess");
export const getBehaviorPermissionsFailure = createSagaAction<{error: any, requestPayload: PayloadGetBehaviorPermissions}>("getBehaviorPermissionsFailure");

export const getBehaviorPermissions = createSagaAction<PayloadGetBehaviorPermissions>("getBehaviorPermissions");

export function *getBehaviorPermissionsSaga() {
    yield takeLatest(getBehaviorPermissions, getBehaviorPermissionsSagaImp);
}

export function *getBehaviorPermissionsSagaImp(_action_: Action<PayloadGetBehaviorPermissions>) {
    const {markErrorsAsHandled, ..._payloadRest_} = _action_.payload;
    try {
        const {
            behaviorId,
        } = _payloadRest_;

        yield put(getBehaviorPermissionsRequest(_action_.payload));

        const response: Required<GetBehaviorPermissionsResponse> = yield apiCall(Api.behaviorApi, Api.behaviorApi.getBehaviorPermissions,
            parseFloat(behaviorId),
        );

        let successReturnValue: any = undefined;
            successReturnValue = getBehaviorPermissionsResponseRecordUtils.fromApiPassthrough(response);
            yield put(getBehaviorPermissionsSuccess(successReturnValue));

        return successReturnValue;
    } catch (error) {
        if (markErrorsAsHandled) {error.wasHandled = true; }
        yield put(getBehaviorPermissionsFailure({error, requestPayload: _action_.payload}));
        return error;
    }
}
//endregion
//region getBehaviorType

export interface PayloadGetBehaviorType extends PayloadGetBehaviorTypeRequest, BasePayloadApiAction {
}

export interface PayloadGetBehaviorTypeRequest {
    behaviorId: string;
}

export const getBehaviorTypeRequest = createSagaAction<PayloadGetBehaviorTypeRequest>("getBehaviorTypeRequest");
export const getBehaviorTypeSuccess = createSagaAction<BehaviorType>("getBehaviorTypeSuccess");
export const getBehaviorTypeFailure = createSagaAction<{error: any, requestPayload: PayloadGetBehaviorType}>("getBehaviorTypeFailure");

export const getBehaviorType = createSagaAction<PayloadGetBehaviorType>("getBehaviorType");

export function *getBehaviorTypeSaga() {
    yield takeLatest(getBehaviorType, getBehaviorTypeSagaImp);
}

export function *getBehaviorTypeSagaImp(_action_: Action<PayloadGetBehaviorType>) {
    const {markErrorsAsHandled, ..._payloadRest_} = _action_.payload;
    try {
        const {
            behaviorId,
        } = _payloadRest_;

        yield put(getBehaviorTypeRequest(_action_.payload));

        const response: Required<GetBehaviorTypeResponse> = yield apiCall(Api.behaviorApi, Api.behaviorApi.getBehaviorType,
            parseFloat(behaviorId),
        );

        let successReturnValue: any = undefined;
            successReturnValue = getBehaviorTypeResponseRecordUtils.fromApiPassthrough(response);
            yield put(getBehaviorTypeSuccess(successReturnValue));

        return successReturnValue;
    } catch (error) {
        if (markErrorsAsHandled) {error.wasHandled = true; }
        yield put(getBehaviorTypeFailure({error, requestPayload: _action_.payload}));
        return error;
    }
}
//endregion
