import { AppObjectUC, getSingletonComponent, } from "@vived/core";
import { AppDispatcher } from "../Entities/AppDispatcher";
export class SubmitResultResultUC extends AppObjectUC {
    constructor() {
        super(...arguments);
        this.requestType = "SUBMIT_RESULTS";
    }
}
SubmitResultResultUC.type = "SubmitResultResultUC";
SubmitResultResultUC.get = (appObjects) => getSingletonComponent(SubmitResultResultUC.type, appObjects);
export function makeSubmitResultUC(appObject) {
    return new SubmitResultResultUCImp(appObject);
}
export function submitHitResult(data, appObjects) {
    const dispatchUC = SubmitResultResultUC.get(appObjects);
    if (dispatchUC) {
        dispatchUC.submitHitResult(data);
    }
    else {
        appObjects.submitWarning("submitHitResult", "Can't find SubmitResultResultUC");
    }
}
export function submitProgressResult(data, appObjects) {
    const dispatchUC = SubmitResultResultUC.get(appObjects);
    if (dispatchUC) {
        dispatchUC.submitProgressResult(data);
    }
    else {
        appObjects.submitWarning("submitProgressResult", "Can't find SubmitResultResultUC");
    }
}
export function submitQualityResult(data, appObjects) {
    const dispatchUC = SubmitResultResultUC.get(appObjects);
    if (dispatchUC) {
        dispatchUC.submitQualityResult(data);
    }
    else {
        appObjects.submitWarning("submitQualityResult", "Can't find SubmitResultResultUC");
    }
}
export function submitScoreResult(data, appObjects) {
    const dispatchUC = SubmitResultResultUC.get(appObjects);
    if (dispatchUC) {
        dispatchUC.submitScoreResult(data);
    }
    else {
        appObjects.submitWarning("submitScoreResult", "Can't find SubmitResultResultUC");
    }
}
export function submitMultiHitResult(data, appObjects) {
    const dispatchUC = SubmitResultResultUC.get(appObjects);
    if (dispatchUC) {
        dispatchUC.submitMultiHitResult(data);
    }
    else {
        appObjects.submitWarning("submitMultiHitResult", "Can't find SubmitResultResultUC");
    }
}
class SubmitResultResultUCImp extends SubmitResultResultUC {
    constructor(appObject) {
        super(appObject, SubmitResultResultUC.type);
        this.requestVersion = 3;
        this.submitHitResult = (data) => {
            if (!this.appDispatcher)
                return;
            const { description, success } = data;
            const payload = {
                resultType: "HIT_V1",
                description,
                result: {
                    success,
                },
            };
            this.appDispatcher.formRequestAndDispatch("SUBMIT_RESULTS", 3, payload);
        };
        this.submitProgressResult = (data) => {
            if (!this.appDispatcher)
                return;
            const { description, progress } = data;
            const payload = {
                resultType: "PROGRESS_V1",
                description,
                result: {
                    progress,
                },
            };
            this.appDispatcher.formRequestAndDispatch("SUBMIT_RESULTS", 3, payload);
        };
        this.submitMultiHitResult = (data) => {
            if (!this.appDispatcher)
                return;
            const { description, hits, misses, unanswered } = data;
            const payload = {
                resultType: "MULTIHIT_V1",
                description,
                result: {
                    hits,
                    misses,
                    unanswered,
                },
            };
            this.appDispatcher.formRequestAndDispatch("SUBMIT_RESULTS", 3, payload);
        };
        this.submitQualityResult = (data) => {
            if (!this.appDispatcher)
                return;
            const { description, stars, maxStars } = data;
            const payload = {
                resultType: "QUALITY_V1",
                description,
                result: {
                    stars,
                    maxStars,
                },
            };
            this.appDispatcher.formRequestAndDispatch("SUBMIT_RESULTS", 3, payload);
        };
        this.submitScoreResult = (data) => {
            if (!this.appDispatcher)
                return;
            const { description, score, maxScore } = data;
            const payload = {
                resultType: "SCORE_V1",
                description,
                result: {
                    score,
                    maxScore,
                },
            };
            this.appDispatcher.formRequestAndDispatch("SUBMIT_RESULTS", 3, payload);
        };
        this.appDispatcher = appObject.getComponent(AppDispatcher.type);
        if (!this.appDispatcher) {
            this.warn("DispatchStateChangeUC has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first");
            this.dispose();
        }
    }
}
//# sourceMappingURL=SubmitResultResultUC.js.map