"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PreviewSchemaService = void 0;
const preview_app_constants_1 = require("./preview-app-constants");
const yok_1 = require("../../../common/yok");
const _ = require("lodash");
class PreviewSchemaService {
    constructor($errors, $projectDataService) {
        this.$errors = $errors;
        this.$projectDataService = $projectDataService;
        this.previewSchemas = {
            nsplay: {
                name: "nsplay",
                scannerAppId: "org.nativescript.play",
                scannerAppStoreId: "1263543946",
                previewAppId: "org.nativescript.preview",
                previewAppStoreId: "1264484702",
                msvKey: "cli",
                publishKey: preview_app_constants_1.PubnubKeys.PUBLISH_KEY,
                subscribeKey: preview_app_constants_1.PubnubKeys.SUBSCRIBE_KEY,
                default: true,
            },
            kspreview: {
                name: "kspreview",
                scannerAppId: "com.kinvey.scanner",
                scannerAppStoreId: "1458317125",
                previewAppId: "com.kinvey.preview",
                previewAppStoreId: "1458502055",
                msvKey: "kinveyStudio",
                publishKey: preview_app_constants_1.PubnubKeys.PUBLISH_KEY,
                subscribeKey: preview_app_constants_1.PubnubKeys.SUBSCRIBE_KEY,
            },
        };
    }
    getSchemaData(projectDir) {
        let schemaName = this.getSchemaNameFromProject(projectDir);
        if (!schemaName) {
            schemaName = _.findKey(this.previewSchemas, (previewSchema) => previewSchema.default);
        }
        const result = this.previewSchemas[schemaName];
        if (!result) {
            this.$errors.fail(`Invalid schema. The valid schemas are ${_.keys(this.previewSchemas)}.`);
        }
        return result;
    }
    getSchemaNameFromProject(projectDir) {
        try {
            const projectData = this.$projectDataService.getProjectData(projectDir);
            return projectData.previewAppSchema;
        }
        catch (err) {
        }
        return null;
    }
}
exports.PreviewSchemaService = PreviewSchemaService;
yok_1.injector.register("previewSchemaService", PreviewSchemaService);
