"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SerializeChallengeUC = void 0;
const core_1 = require("@vived/core");
const StateMachine_1 = require("../../StateMachine");
const ChallengeEntity_1 = require("../Entities/ChallengeEntity");
class SerializeChallengeUC extends core_1.AppObjectUC {
    get challenge() {
        return this.getCachedSingleton(ChallengeEntity_1.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 = StateMachine_1.StateMachineEntity.get(appObject.appObjectRepo);
        if (stateMachine) {
            stateMachine.registerSerializedSystem(this);
        }
        else {
            this.error("Unable to find StateMachineEntity");
        }
    }
}
exports.SerializeChallengeUC = SerializeChallengeUC;
SerializeChallengeUC.type = "SerializeChallengeUC";
//# sourceMappingURL=SerializeChallenge.js.map