"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizePlaydropWebBase = normalizePlaydropWebBase;
exports.getAppTypeSlug = getAppTypeSlug;
exports.buildPlatformPlayUrl = buildPlatformPlayUrl;
exports.buildPlatformDevUrl = buildPlatformDevUrl;
exports.buildUploadLaunchCheckUrl = buildUploadLaunchCheckUrl;
const DEFAULT_WEB_BASE = 'https://www.playdrop.ai';
function normalizePlaydropWebBase(webBase) {
    const base = typeof webBase === 'string' && webBase.trim().length > 0 ? webBase.trim() : DEFAULT_WEB_BASE;
    return base.replace(/\/$/, '');
}
function getAppTypeSlug(type) {
    if (typeof type !== 'string') {
        return 'game';
    }
    switch (type) {
        case 'DEMO':
            return 'demo';
        case 'TOOL':
            return 'tool';
        case 'TEMPLATE':
            return 'template';
        case 'GAME':
        default:
            return 'game';
    }
}
function buildPlatformPlayUrl(webBase, input) {
    const base = normalizePlaydropWebBase(webBase);
    const creator = encodeURIComponent(input.creatorUsername);
    const typeSlug = getAppTypeSlug(input.appType);
    const appName = encodeURIComponent(input.appName);
    return `${base}/creators/${creator}/apps/${typeSlug}/${appName}/play`;
}
function buildPlatformDevUrl(webBase, input) {
    const base = normalizePlaydropWebBase(webBase);
    const creator = encodeURIComponent(input.creatorUsername);
    const typeSlug = getAppTypeSlug(input.appType);
    const appName = encodeURIComponent(input.appName);
    const url = new URL(`${base}/creators/${creator}/apps/${typeSlug}/${appName}/dev`);
    if (typeof input.devAuth === 'string' && input.devAuth.trim().length > 0) {
        url.searchParams.set('devAuth', input.devAuth.trim());
    }
    if (typeof input.player === 'string' && input.player.trim().length > 0) {
        url.searchParams.set('player', input.player.trim());
    }
    if (input.launchCheck) {
        url.searchParams.set('launchCheck', '1');
    }
    return url.toString();
}
function buildUploadLaunchCheckUrl(webBase, input) {
    const base = normalizePlaydropWebBase(webBase);
    const creator = encodeURIComponent(input.creatorUsername);
    const typeSlug = getAppTypeSlug(input.appType);
    const appName = encodeURIComponent(input.appName);
    const sessionId = encodeURIComponent(input.sessionId);
    return `${base}/creators/${creator}/apps/${typeSlug}/${appName}/upload-check/${sessionId}`;
}
