import { AppObjectUC } from "@vived/core";
import { StateMachineEntity } from "../../StateMachine";
import { ObjectPickEntity } from "../Entities/ObjectPickEntity";
export class SerializeObjectPick extends 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.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 = StateMachineEntity.get(appObject.appObjectRepo);
        if (stateMachine) {
            stateMachine.registerSerializedSystem(this);
        }
        else {
            this.warn("Unable to find StateMachineEntity");
        }
    }
}
SerializeObjectPick.type = "SerializeObjectPick";
//# sourceMappingURL=SerializeObjectPick.js.map