"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@restlessness/core");
class Route {
    static parseFromText(text) {
        const route = new Route();
        const params = text
            .split('/')
            .filter(p => p !== '')
            .map(p => {
            if (p[0] === '{') {
                return '{' + core_1.Misc.camelCaseToDash(p
                    .replace('{', '')
                    .replace('}', '')) + '}';
            }
            return p;
        });
        route.params = params;
        return route;
    }
    get endpointRoute() {
        return '/' + this.functionPath;
    }
    get folderName() {
        const params = [
            ...this.params,
        ];
        const models = params
            .filter(p => p[0] !== '{');
        const variables = params
            .filter(p => p[0] === '{')
            .map(p => p.replace('{', '').replace('}', ''));
        return `${models.join('-')}${variables.length ? '-by-' : ''}${variables.join('-and-')}`;
    }
    get functionName() {
        const params = [
            ...this.params,
        ];
        const models = params
            .filter(p => p[0] !== '{')
            .map(p => p
            .split('-')
            .map(p => core_1.Misc.capitalize(p))
            .join(''));
        const variables = params
            .filter(p => p[0] === '{')
            .map(p => p
            .replace('{', '')
            .replace('}', '')
            .split('-')
            .map(p => core_1.Misc.capitalize(p))
            .join(''));
        return `${models.join('')}${variables.length ? 'By' : ''}${variables.join('And')}`;
    }
    get functionPath() {
        const params = [
            ...this.params,
        ];
        return params
            .map(p => {
            if (p[0] === '{') {
                return `{${p
                    .replace('{', '')
                    .replace('}', '')
                    .split('-')
                    .map((p2, index) => !index ? p2 : core_1.Misc.capitalize(p2))
                    .join('')}}`;
            }
            return p;
        })
            .join('/');
    }
    toString() {
        return this.endpointRoute;
    }
    toJSON() {
        return this.endpointRoute;
    }
    get vars() {
        return this.params
            .filter(p => p[0] === '{')
            .map(p => p
            .replace('{', '')
            .replace('}', '')
            .split('-')
            .map((p2, index) => !index ? p2 : core_1.Misc.capitalize(p2))
            .join(''));
    }
}
exports.default = Route;
//# sourceMappingURL=index.js.map