"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SerializeObjectPick = void 0;
const core_1 = require("@vived/core");
const StateMachine_1 = require("../../StateMachine");
const ObjectPickEntity_1 = require("../Entities/ObjectPickEntity");
class SerializeObjectPick extends core_1.AppObjectUC {
    getSystemState() {
        const state = {
            correctObjectIds: this.objectPick.correctObjectIds,
        };
        return state;
    }
    applySystemState(state, version) {
        if (version === 1) {
            this.applyStateV1(state);
        }
        else {
            this.applyDefaultState();
        }
    }
    applyStateV1(state) {
        if (state.correctObjectIds === undefined) {
            this.applyDefaultState();
            return;
        }
        this.objectPick.clearCorrectObjectIds();
        state.correctObjectIds.forEach((id) => {
            this.objectPick.addCorrectObjectId(id);
        });
    }
    applyDefaultState() {
        this.objectPick.clearCorrectObjectIds();
    }
    constructor(appObject) {
        super(appObject, SerializeObjectPick.type);
        this.name = "object-pick";
        this.seriliziationVersion = 1;
        const objectPick = ObjectPickEntity_1.ObjectPickEntity.get(this.appObjects);
        if (!objectPick) {
            throw new Error("[SerializeObjectPick] App Object does not have a Object Pick Entity. Add one");
        }
        this.objectPick = objectPick;
        const stateMachine = StateMachine_1.StateMachineEntity.get(appObject.appObjectRepo);
        if (stateMachine) {
            stateMachine.registerSerializedSystem(this);
        }
        else {
            this.warn("Unable to find StateMachineEntity");
        }
    }
}
exports.SerializeObjectPick = SerializeObjectPick;
SerializeObjectPick.type = "SerializeObjectPick";
//# sourceMappingURL=SerializeObjectPick.js.map