
class StartRamp {

    static initStartRamp() {
        if (window.sigApi !== undefined) {
            const fm = new StartRamp(window.sigApi);
        } else {
            // ist sigApi noch nicht geladen, als EventListener fuer 'SigApiReady' registrieren
            window.addEventListener('SigApiReady', () => {
                const fm = new StartRamp(window.sigApi);
            });
        }
    }

    constructor(api) {
        this.events = null;
        this.eventMediator = null;
        this.datapointAPI = null;
        this._initAPIs(api);
        this._registerEvents();
    }


    _initAPIs(api) {
        if ((api !== null) && (api !== undefined)) {
            if (api.datapointManager !== undefined) {
                this.datapointAPI = api.datapointManager;
            }
            if (api.eventMediator !== undefined) {
                this.eventMediator = api.eventMediator;
            }
            if (api.events !== undefined) {
                this.events = api.events;
            }
        }
    }

    _registerEvents() {

        let i;
        let PowerLimitation = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];

        if ((this.eventMediator !== null) && (this.eventMediator !== undefined) && (this.events !== null) && (this.events !== undefined)) {
            this.eventMediator.subscribe(this.events.getUserDefinedInternalEvent('RampStart'), () => {
                this.datapointAPI.readDataPoint('10:Zone1.PowerLimitationVal', 0)
                    .then((resolve) => {
                        PowerLimitation[0] = resolve.value;
                        this.datapointAPI.readDataPoint('10:Zone2.PowerLimitationVal', 0)
                            .then((resolve) => {
                                PowerLimitation[1] = resolve.value;
                                this.datapointAPI.readDataPoint('10:Zone3.PowerLimitationVal', 0)
                                    .then((resolve) => {
                                        PowerLimitation[2] = resolve.value;
                                        this.datapointAPI.readDataPoint('10:Zone4.PowerLimitationVal', 0)
                                            .then((resolve) => {
                                                PowerLimitation[3] = resolve.value;
                                                this.datapointAPI.readDataPoint('10:Zone5.PowerLimitationVal', 0)
                                                    .then((resolve) => {
                                                        PowerLimitation[4] = resolve.value;
                                                        this.datapointAPI.readDataPoint('10:Zone6.PowerLimitationVal', 0)
                                                            .then((resolve) => {
                                                                PowerLimitation[5] = resolve.value;
                                                                this.datapointAPI.readDataPoint('10:Zone7.PowerLimitationVal', 0)
                                                                    .then((resolve) => {
                                                                        PowerLimitation[6] = resolve.value;
                                                                        this.datapointAPI.readDataPoint('10:Zone8.PowerLimitationVal', 0)
                                                                            .then((resolve) => {
                                                                                PowerLimitation[7] = resolve.value;
                                                                                this.datapointAPI.readDataPoint('10:Zone9.PowerLimitationVal', 0)
                                                                                    .then((resolve) => {
                                                                                        PowerLimitation[8] = resolve.value;
                                                                                        this.datapointAPI.readDataPoint('10:Zone10.PowerLimitationVal', 0)
                                                                                            .then((resolve) => {
                                                                                                PowerLimitation[9] = resolve.value;
                                                                                                this.datapointAPI.readDataPoint('10:Zone11.PowerLimitationVal', 0)
                                                                                                    .then((resolve) => {
                                                                                                        PowerLimitation[10] = resolve.value;
                                                                                                        this.datapointAPI.readDataPoint('10:Zone12.PowerLimitationVal', 0)
                                                                                                            .then((resolve) => {
                                                                                                                PowerLimitation[11] = resolve.value;
                                                                                                                this.datapointAPI.readDataPoint('10:Zone13.PowerLimitationVal', 0)
                                                                                                                    .then((resolve) => {
                                                                                                                        PowerLimitation[12] = resolve.value;
                                                                                                                        this.datapointAPI.readDataPoint('10:Zone14.PowerLimitationVal', 0)
                                                                                                                            .then((resolve) => {
                                                                                                                                PowerLimitation[13] = resolve.value;
                                                                                                                                this.datapointAPI.readDataPoint('10:Zone15.PowerLimitationVal', 0)
                                                                                                                                    .then((resolve) => {
                                                                                                                                        PowerLimitation[14] = resolve.value;
                                                                                                                                        this.datapointAPI.readDataPoint('10:Zone16.PowerLimitationVal', 0)
                                                                                                                                            .then((resolve) => {
                                                                                                                                                PowerLimitation[15] = resolve.value;
                                                                                                                                                this.datapointAPI.readDataPoint('10:Zone17.PowerLimitationVal', 0)
                                                                                                                                                    .then((resolve) => {
                                                                                                                                                        PowerLimitation[16] = resolve.value;
                                                                                                                                                        this.datapointAPI.readDataPoint('10:Zone18.PowerLimitationVal', 0)
                                                                                                                                                            .then((resolve) => {
                                                                                                                                                                PowerLimitation[17] = resolve.value;
                                                                                                                                                                this.datapointAPI.readDataPoint('10:Zone19.PowerLimitationVal', 0)
                                                                                                                                                                    .then((resolve) => {
                                                                                                                                                                        PowerLimitation[18] = resolve.value;
                                                                                                                                                                        this.datapointAPI.readDataPoint('10:Zone20.PowerLimitationVal', 0)
                                                                                                                                                                            .then((resolve) => {
                                                                                                                                                                                PowerLimitation[19] = resolve.value;
                                                                                                                                                                                this.datapointAPI.readDataPoint('10:Zone21.PowerLimitationVal', 0)
                                                                                                                                                                                    .then((resolve) => {
                                                                                                                                                                                        PowerLimitation[20] = resolve.value;
                                                                                                                                                                                        this.datapointAPI.readDataPoint('10:Zone22.PowerLimitationVal', 0)
                                                                                                                                                                                            .then((resolve) => {
                                                                                                                                                                                                PowerLimitation[21] = resolve.value;
                                                                                                                                                                                                this.datapointAPI.readDataPoint('10:Zone23.PowerLimitationVal', 0)
                                                                                                                                                                                                    .then((resolve) => {
                                                                                                                                                                                                        PowerLimitation[22] = resolve.value;
                                                                                                                                                                                                        this.datapointAPI.readDataPoint('10:Zone24.PowerLimitationVal', 0)
                                                                                                                                                                                                            .then((resolve) => {
                                                                                                                                                                                                                PowerLimitation[23] = resolve.value;

                                                                                                                                                                                                                                     //   this.datapointAPI.readDataPoint('10:Global_Set1.ZielSollTemperaturRampe', 0)
                                                                                                                                                                                                                                       //     .then((resolve) => {
                                                                                                                                                                                                                                               // this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', resolve.value);



                                                                                                                                                                                                                for (i = 0; i < 24; i++) {


                                                                                                                                                                                                                                                                                                                    if (PowerLimitation[i] !== 0)  {
                                                                                                                                                                                                                                                                                                                        this.setParameter(i, 5);
                                                                                                                                                                                                                                                                                                                    }

                                                                                                                                                                                                                                                                                                                }

                                                                                                                                                                                                                                                                                                            });});});});});});});});});});});});});});//});
                                                                                    });});});});});});});});});





            });


            });


            this.eventMediator.subscribe(this.events.getUserDefinedInternalEvent('RampEnd'), () => {



                                                                                                                                                                                                                      //  this.datapointAPI.writeDataPoint('10:PIDGroup1.SetPoint', 2000);




                for (i = 0; i < 24; i++) {


                                                                                                                                                                                                                            if (PowerLimitation[i] !== 0)  {
                                                                                                                                                                                                                                this.setParameter(i, 6);
                                                                                                                                                                                                                            }

                                                                                                                                                                                                                        }










            });



        }
    }


    setParameter(i,k){

        switch (i) {
            case 0:
                   this.datapointAPI.writeDataPoint('10:Zone1.TestNewStart', k);
                   if (k === 5) {
                      // this.datapointAPI.writeDataPoint('10:Zone1.GroupID', 11);
                     //  this.datapointAPI.writeDataPoint('10:Zone1.flagGroupID', 1);
                     //  this.datapointAPI.writeDataPoint('10:Zone1.SetPoint', n);
                   }
                   break;

            case 1:
                   this.datapointAPI.writeDataPoint('10:Zone2.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone2.GroupID', 11);
                    //this.datapointAPI.writeDataPoint('10:Zone2.flagGroupID', 1);
                    //this.datapointAPI.writeDataPoint('10:Zone2.SetPoint', n);
                }
                break;
            case 2:
                  this.datapointAPI.writeDataPoint('10:Zone3.TestNewStart', k);
                if (k === 5) {
                 //   this.datapointAPI.writeDataPoint('10:Zone3.GroupID', 11);
                   // this.datapointAPI.writeDataPoint('10:Zone3.flagGroupID', 1);
                   // this.datapointAPI.writeDataPoint('10:Zone3.SetPoint', n);
                }
                break;
            case 3:
                    this.datapointAPI.writeDataPoint('10:Zone4.TestNewStart', k);
                if (k === 5) {
                   // this.datapointAPI.writeDataPoint('10:Zone4.GroupID', 11);
                    //this.datapointAPI.writeDataPoint('10:Zone4.flagGroupID', 1);
                   // this.datapointAPI.writeDataPoint('10:Zone4.SetPoint', n);
                }
                break;
            case 4:
                    this.datapointAPI.writeDataPoint('10:Zone5.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone5.GroupID', 11);
                   // this.datapointAPI.writeDataPoint('10:Zone5.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone5.SetPoint', n);
                }
                break;
            case 5:
                   this.datapointAPI.writeDataPoint('10:Zone6.TestNewStart', k);
                if (k === 5) {
                   // this.datapointAPI.writeDataPoint('10:Zone6.GroupID', 11);
                   // this.datapointAPI.writeDataPoint('10:Zone6.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone6.SetPoint', n);
                }
                break;
            case 6:
                    this.datapointAPI.writeDataPoint('10:Zone7.TestNewStart', k);
                if (k === 5) {
                   // this.datapointAPI.writeDataPoint('10:Zone7.GroupID', 11);
                   // this.datapointAPI.writeDataPoint('10:Zone7.flagGroupID', 1);
                 //   this.datapointAPI.writeDataPoint('10:Zone7.SetPoint', n);
                }
                break;
            case 7:
                  this.datapointAPI.writeDataPoint('10:Zone8.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone8.GroupID', 11);
                   // this.datapointAPI.writeDataPoint('10:Zone8.flagGroupID', 1);
                 //   this.datapointAPI.writeDataPoint('10:Zone8.SetPoint', n);
                }
                break;
            case 8:
                    this.datapointAPI.writeDataPoint('10:Zone9.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone9.GroupID', 11);
                   // this.datapointAPI.writeDataPoint('10:Zone9.flagGroupID', 1);
                   // this.datapointAPI.writeDataPoint('10:Zone9.SetPoint', n);
                }
                break;
            case 9:
                   this.datapointAPI.writeDataPoint('10:Zone10.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone10.GroupID', 11);
                   // this.datapointAPI.writeDataPoint('10:Zone10.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone10.SetPoint', n);
                }
                break;
            case 10:
                   this.datapointAPI.writeDataPoint('10:Zone11.TestNewStart', k);
                if (k === 5) {
                   // this.datapointAPI.writeDataPoint('10:Zone11.GroupID', 11);
                   // this.datapointAPI.writeDataPoint('10:Zone11.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone11.SetPoint', n);
                }
                break;
            case 11:
                    this.datapointAPI.writeDataPoint('10:Zone12.TestNewStart', k);
                if (k === 5) {
                 //   this.datapointAPI.writeDataPoint('10:Zone12.GroupID', 11);
                  //  this.datapointAPI.writeDataPoint('10:Zone12.flagGroupID', 1);
                 //   this.datapointAPI.writeDataPoint('10:Zone12.SetPoint', n);
                }
                break;
            case 12:
                   this.datapointAPI.writeDataPoint('10:Zone13.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone13.GroupID', 11);
                  //  this.datapointAPI.writeDataPoint('10:Zone13.flagGroupID', 1);
                   // this.datapointAPI.writeDataPoint('10:Zone13.SetPoint', n);
                }
                break;
            case 13:
                     this.datapointAPI.writeDataPoint('10:Zone14.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone14.GroupID', 11);
                  //  this.datapointAPI.writeDataPoint('10:Zone14.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone14.SetPoint', n);
                }
                break;
            case 14:
                    this.datapointAPI.writeDataPoint('10:Zone15.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone15.GroupID', 11);
                  //  this.datapointAPI.writeDataPoint('10:Zone15.flagGroupID', 1);
                 //   this.datapointAPI.writeDataPoint('10:Zone15.SetPoint', n);
                }
                break;
            case 15:
                    this.datapointAPI.writeDataPoint('10:Zone16.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone16.GroupID', 11);
                 //   this.datapointAPI.writeDataPoint('10:Zone16.flagGroupID', 1);
                 //   this.datapointAPI.writeDataPoint('10:Zone16.SetPoint', n);
                }
                break;
            case 16:
                   this.datapointAPI.writeDataPoint('10:Zone17.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone17.GroupID', 11);
                   // this.datapointAPI.writeDataPoint('10:Zone17.flagGroupID', 1);
                 //   this.datapointAPI.writeDataPoint('10:Zone17.SetPoint', n);
                }
                break;
            case 17:
                   this.datapointAPI.writeDataPoint('10:Zone18.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone18.GroupID', 11);
                  //  this.datapointAPI.writeDataPoint('10:Zone18.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone18.SetPoint', n);
                }
                break;
            case 18:
                    this.datapointAPI.writeDataPoint('10:Zone19.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone19.GroupID', 11);
                  //  this.datapointAPI.writeDataPoint('10:Zone19.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone19.SetPoint', n);
                }
                break;
            case 19:
                     this.datapointAPI.writeDataPoint('10:Zone20.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone20.GroupID', 11);
                  //  this.datapointAPI.writeDataPoint('10:Zone20.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone20.SetPoint', n);
                }
                break;
            case 20:
                   this.datapointAPI.writeDataPoint('10:Zone21.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone21.GroupID', 11);
                   // this.datapointAPI.writeDataPoint('10:Zone21.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone21.SetPoint', n);
                }
                break;
            case 21:
                    this.datapointAPI.writeDataPoint('10:Zone22.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone22.GroupID', 11);
                  //  this.datapointAPI.writeDataPoint('10:Zone22.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone22.SetPoint', n);
                }
                break;
            case 22:
                    this.datapointAPI.writeDataPoint('10:Zone23.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone23.GroupID', 11);
                  //  this.datapointAPI.writeDataPoint('10:Zone23.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone23.SetPoint', n);
                }
                break;
            case 23:
                     this.datapointAPI.writeDataPoint('10:Zone24.TestNewStart', k);
                if (k === 5) {
                  //  this.datapointAPI.writeDataPoint('10:Zone24.GroupID', 11);
                   //  this.datapointAPI.writeDataPoint('10:Zone24.flagGroupID', 1);
                  //  this.datapointAPI.writeDataPoint('10:Zone24.SetPoint', n);
                }
                break;
        }
    }
}

StartRamp.initStartRamp();