import { AppObjectUC } from "@vived/core";
import { StateMachineEntity } from "../../StateMachine";
import { ChallengeEntity } from "../Entities/ChallengeEntity";
export class SerializeChallengeUC extends AppObjectUC {
    get challenge() {
        return this.getCachedSingleton(ChallengeEntity.type);
    }
    getSystemState() {
        if (!this.challenge)
            return {};
        const challenge = this.challenge.selectedChallenge;
        const state = {
            challenge,
        };
        return state;
    }
    applySystemState(state, version) {
        if (version === 1) {
            this.applyVersion1(state);
        }
        else {
            this.applyDefaultState();
        }
    }
    applyVersion1(state) {
        if (!this.challenge)
            return;
        this.challenge.selectedChallenge = state.challenge;
    }
    applyDefaultState() {
        if (!this.challenge)
            return;
        this.challenge.selectedChallenge = "NONE";
    }
    constructor(appObject) {
        super(appObject, SerializeChallengeUC.type);
        this.name = "challenge";
        this.seriliziationVersion = 1;
        const stateMachine = StateMachineEntity.get(appObject.appObjectRepo);
        if (stateMachine) {
            stateMachine.registerSerializedSystem(this);
        }
        else {
            this.error("Unable to find StateMachineEntity");
        }
    }
}
SerializeChallengeUC.type = "SerializeChallengeUC";
//# sourceMappingURL=SerializeChallenge.js.map