import { VariableStateEnum } from '../../../communication';
import { EventEmitter } from '@angular/core';
import { VariableUtil } from '../../../utils/variable-util';
import { VariableDefinition } from '../../../communication/variable/variable-definition';
export class RotationObserver {
    constructor(rotationModel, variableCommunicator, variableStore, signalRAppId) {
        this.signalRAppId = signalRAppId;
        this.rotationValueChanged = new EventEmitter();
        if (!rotationModel.variableName) {
            return;
        }
        const variable = new VariableDefinition(rotationModel.variableName, rotationModel.variableGroupName, rotationModel.dataSourceCode, rotationModel.variableVersion);
        const variableName = VariableUtil.getConvertedVariableName(variableStore, variable);
        if (!variableName) {
            return;
        }
        variableCommunicator.subscribeVariableState(variableName).subscribe(variableValue => {
            if (variableValue.state === VariableStateEnum.Normal) {
                variableCommunicator.openVariable(variableName, this.signalRAppId).subscribe(value => {
                    if (value.state === VariableStateEnum.DataNormal) {
                        this.currentValue = value;
                        this.rotationValueChanged.emit(this.currentValue.value);
                    }
                });
            }
        });
    }
}
