"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PositionTemplate = exports.getTemplateFragments = void 0;
const path_1 = __importDefault(require("path"));
const common_1 = require("@nestjs/common");
const _types_1 = require("../../types");
const stack_1 = require("../../utils/stack");
const getTemplateFragments = (filePath) => {
    const filename = path_1.default.basename(filePath);
    const networkFromDir = path_1.default.basename(path_1.default.dirname(filePath));
    const appIdFromDir = path_1.default.basename(path_1.default.resolve(filePath, '..', '..'));
    const [appIdFromFile, groupIdFromFile] = filename.split('.');
    if (!Object.values(_types_1.Network).includes(networkFromDir))
        throw new Error('Invalid network folder name for template');
    if (appIdFromFile !== appIdFromDir)
        throw new Error(`App ID folder/file value mismatch (expected ${appIdFromFile}, actual ${appIdFromDir})`);
    return { network: networkFromDir, appId: appIdFromDir, groupId: groupIdFromFile };
};
exports.getTemplateFragments = getTemplateFragments;
const PositionTemplate = () => {
    return (target) => {
        const [, , , templateFile] = (0, stack_1.getStack)();
        try {
            const { appId, groupId, network } = (0, exports.getTemplateFragments)(templateFile.getFileName());
            target.prototype.appId = appId;
            target.prototype.network = network;
            target.prototype.groupId = groupId;
        }
        catch (e) {
            console.error(e);
        }
        return (0, common_1.Injectable)()(target);
    };
};
exports.PositionTemplate = PositionTemplate;
//# sourceMappingURL=position-template.decorator.js.map